Repository: LMFDB/lmfdb

Issue:
Rewrite broken for number field database
I tried rewrite with the identity function as the modification function:

```
from lmfdb import db
def nmod(ent):
    return ent
db.nf_fields.rewrite(nmod)
```

and get the error

Traceback (most recent call last):
  File "/home/jj/lmfdb/lmfdb/backend/base.py", line 313, in _execute
    cur.execute(query, values)
psycopg2.errors.UndefinedColumn: column "zk" of relation "nf_fields_tmp" does not exist
LINE 1: ...ling" = "tmp_update_from_file"."minimal_sibling", "zk" = "tm...
                                                             ^


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "nfmod.py", line 39, in <module>
    db.nf_fields.rewrite(nmod) #,datafile='/home/jj/nf-lmfdb/DELETE.ME')
  File "/home/jj/lmfdb/lmfdb/backend/table.py", line 1005, in rewrite
    self.update_from_file(
  File "/home/jj/lmfdb/lmfdb/backend/table.py", line 1124, in update_from_file
    self._execute(updater.format(
  File "/home/jj/lmfdb/lmfdb/backend/base.py", line 319, in _execute
    reraise(type(e), type(e)(str(e) + context), sys.exc_info()[2])
  File "/home/jj/lmfdb/lmfdb/backend/utils.py", line 230, in reraise
    raise exc_value.with_traceback(exc_traceback)
  File "/home/jj/lmfdb/lmfdb/backend/base.py", line 313, in _execute
    cur.execute(query, values)
psycopg2.errors.UndefinedColumn: column "zk" of relation "nf_fields_tmp" does not exist
LINE 1: ...ling" = "tmp_update_from_file"."minimal_sibling", "zk" = "tm...
 
 happens while executing b'UPDATE "nf_fields_tmp" SET "label" = "tmp_update_from_file"."label", "degree" = "tmp_update_from_file"."degree", "r2" = "tmp_update_from_file"."r2", "cm" = "tmp_update_from_file"."cm", "iso_number" = "tmp_update_from_file"."iso_number", "disc_abs" = "tmp_update_from_file"."disc_abs", "disc_sign" = "tmp_update_from_file"."disc_sign", "disc_rad" = "tmp_update_from_file"."disc_rad", "galt" = "tmp_update_from_file"."galt", "class_number" = "tmp_update_from_file"."class_number", "class_group" = "tmp_update_from_file"."class_group", "used_grh" = "tmp_update_from_file"."used_grh", "rd" = "tmp_update_from_file"."rd", "regulator" = "tmp_update_from_file"."regulator", "ramps" = "tmp_update_from_file"."ramps", "coeffs" = "tmp_update_from_file"."coeffs", "num_ram" = "tmp_update_from_file"."num_ram", "conductor" = "tmp_update_from_file"."conductor", "subfields" = "tmp_update_from_file"."subfields", "subfield_mults" = "tmp_update_from_file"."subfield_mults", "torsion_order" = "tmp_update_from_file"."torsion_order", "galois_label" = "tmp_update_from_file"."galois_label", "is_galois" = "tmp_update_from_file"."is_galois", "gal_is_abelian" = "tmp_update_from_file"."gal_is_abelian", "gal_is_cyclic" = "tmp_update_from_file"."gal_is_cyclic", "gal_is_solvable" = "tmp_update_from_file"."gal_is_solvable", "local_algs" = "tmp_update_from_file"."local_algs", "inessentialp" = "tmp_update_from_file"."inessentialp", "index" = "tmp_update_from_file"."index", "monogenic" = "tmp_update_from_file"."monogenic", "embeddings_gen_real" = "tmp_update_from_file"."embeddings_gen_real", "embeddings_gen_imag" = "tmp_update_from_file"."embeddings_gen_imag", "is_minimal_sibling" = "tmp_update_from_file"."is_minimal_sibling", "minimal_sibling" = "tmp_update_from_file"."minimal_sibling", "zk" = "tmp_update_from_file"."zk", "units" = "tmp_update_from_file"."units", "unitsGmodule" = "tmp_update_from_file"."unitsGmodule", "unitsType" = "tmp_update_from_file"."unitsType", "res" = "tmp_update_from_file"."res", "frobs" = "tmp_update_from_file"."frobs", "torsion_gen" = "tmp_update_from_file"."torsion_gen", "dirichlet_group" = "tmp_update_from_file"."dirichlet_group", "subfield_inclusions" = "tmp_update_from_file"."subfield_inclusions", "source" = "tmp_update_from_file"."source" FROM "tmp_update_from_file" WHERE "nf_fields_tmp"."id" = "tmp_update_from_file"."id"'


Discussion:

Resolving patch:
diff --git a/lmfdb/backend/table.py b/lmfdb/backend/table.py
--- a/lmfdb/backend/table.py
+++ b/lmfdb/backend/table.py
@@ -1054,7 +1054,7 @@ def update_from_file(
                 raise ValueError("You must specify a column that is contained in the datafile and uniquely specifies each row")
         with open(datafile) as F:
             tables = [self.search_table]
-            columns = self.search_cols
+            columns = list(self.search_cols)
             if self.extra_table is not None:
                 tables.append(self.extra_table)
                 columns.extend(self.extra_cols)
@@ -1142,7 +1142,7 @@ def drop_tmp():
                 ordered = False
             if etable is not None:
                 ecols = SQL(", ").join([
-                    SQL("{0} = {1}.{0}").format(col, Identifier(tmp_table))
+                    SQL("{0} = {1}.{0}").format(Identifier(col), Identifier(tmp_table))
                     for col in ecols
                 ])
                 self._execute(updater.format(


Test patch:
diff --git a/lmfdb/groups/abstract/test_abstract_groups.py b/lmfdb/groups/abstract/test_abstract_groups.py
--- a/lmfdb/groups/abstract/test_abstract_groups.py
+++ b/lmfdb/groups/abstract/test_abstract_groups.py
@@ -92,5 +92,4 @@ def test_underlying_data(self):
         self.check_args("/Groups/Abstract/sdata/16.8.2.b1.a1", [
             "gps_subgroups", "16.8.2.b1.a1",
             "gps_groups", "[28776, 16577, 5167]", # perm_gens
-            "[16582, 136, 5167, 40176]", # perm_gens
             "[[1, 1, 1]]"]) # faithful_reps