internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: LMFDB/lmfdb

Issue:
Galois orbits for trivial characters shouldn't be empty
Right now (on pages such as http://www.lmfdb.org/Character/Dirichlet/13/1 ), the Galois orbit is empty. Of course, the character is in its own orbit.

I'm making this issue partially as a note-to-self. I will fix this later.


Discussion:

Resolving patch:
diff --git a/lmfdb/WebCharacter.py b/lmfdb/WebCharacter.py
--- a/lmfdb/WebCharacter.py
+++ b/lmfdb/WebCharacter.py
@@ -843,8 +843,9 @@ def galoisorbit(self):
         mod, num = self.modulus, self.number
         prim = self.isprimitive
         #beware this **must** be a generator
-        orbit = ( power_mod(num, k, mod) for k in xsrange(1, order) if gcd(k, order) == 1) # use xsrange not xrange
-        return ( self._char_desc(num, prim=prim) for num in orbit )
+        orbit = (power_mod(num, k, mod) for k in xsrange(1, order + 1)
+                 if gcd(k, order) == 1)
+        return (self._char_desc(num, prim=prim) for num in orbit)
 
     def symbol_numerator(self):
         """ chi is equal to a kronecker symbol if and only if it is real """
@@ -920,7 +921,7 @@ def indlabel(self):
 
     @property
     def codeinducing(self):
-        return { 'sage': 'sage: chi.primitive_character()',
+        return { 'sage': 'chi.primitive_character()',
                  'pari': ['znconreyconductor(g,chi,&chi0)','chi0'] }
 
     @property
@@ -972,7 +973,7 @@ def gauss_sum(self, val):
         chitex = self.char2tex(mod, num, tag=False)
         chitexr = self.char2tex(mod, num, 'r', tag=False)
         deftex = r'\sum_{r\in %s} %s e\left(\frac{%s}{%s}\right)'%(Gtex,chitexr,n,d)
-        return r"\(\displaystyle \tau_{%s}(%s) = %s = %s. \)" % (val, chitex, deftex, g)
+        return r"\(\displaystyle \tau_{%s}(%s) = %s = %s \)" % (val, chitex, deftex, g)
 
     @property
     def codegauss(self):
@@ -995,7 +996,7 @@ def jacobi_sum(self, val):
         psitex1r = self.char2tex(mod, val, '1-r', tag=False)
         deftex = r'\sum_{r\in %s} %s %s'%(Gtex,chitexr,psitex1r)
         from sage.all import latex
-        return r"\( \displaystyle J(%s,%s) = %s = %s.\)" % (chitex, psitex, deftex, latex(jacobi_sum))
+        return r"\( \displaystyle J(%s,%s) = %s = %s \)" % (chitex, psitex, deftex, latex(jacobi_sum))
 
     @property
     def codejacobi(self):
@@ -1019,7 +1020,7 @@ def kloosterman_sum(self, arg):
         \( \displaystyle K(%s,%s,\chi_{%s}(%s,&middot;))
         = \sum_{r \in \Z/%s\Z}
              \chi_{%s}(%s,r) e\left(\frac{%s r + %s r^{-1}}{%s}\right)
-        = %s. \)""" % (a, b, modulus, number, modulus, modulus, number, a, b, modulus, k)
+        = %s \)""" % (a, b, modulus, number, modulus, modulus, number, a, b, modulus, k)
 
     @property
     def codekloosterman(self):


Test patch:
Repository: LMFDB/lmfdb

Issue:
Riemann zeta, value L(1/2) not computed?
It's a bit strange that we say L(1/2) : value not computed for the Riemann zeta function.  This isn't the pole, and its value could be estimated from the Z-function.  


Discussion:

Resolving patch:
diff --git a/lmfdb/lfunctions/Lfunction.py b/lmfdb/lfunctions/Lfunction.py
--- a/lmfdb/lfunctions/Lfunction.py
+++ b/lmfdb/lfunctions/Lfunction.py
@@ -430,14 +430,14 @@ def __init__(self, **args):
         self.texnamecompleted1ms = "\\xi(1-s)"
         self.credit = 'Sage'
 
+        # Generate a function to do computations
+        self.sageLfunction = lc.Lfunction_Zeta()
+
         # Initiate the dictionary info that contains the data for the webpage
         self.info = self.general_webpagedata()
         self.info['knowltype'] = "riemann"
         self.info['title'] = "Riemann Zeta-function: $\\zeta(s)$"
 
-        # Generate a function to do computations
-        self.sageLfunction = lc.Lfunction_Zeta()
-
 #############################################################################
 
 
diff --git a/lmfdb/lfunctions/Lfunction_base.py b/lmfdb/lfunctions/Lfunction_base.py
--- a/lmfdb/lfunctions/Lfunction_base.py
+++ b/lmfdb/lfunctions/Lfunction_base.py
@@ -197,6 +197,10 @@ def general_webpagedata(self):
             info['rank'] = self.order_of_vanishing
             info['motivic_weight'] = r'\(%d\)' % self.motivic_weight
 
+        elif self.Ltype() == "riemann":
+            info['sv_edge'] = r"\[\zeta(1) \approx $\infty$\]"
+            info['sv_critical'] = r"\[\zeta(1/2) \approx -1.460354508\]"
+
         elif self.Ltype() != "artin" or (self.Ltype() == "artin" and self.sign != 0):
             try:
                 info['sv_edge'] = specialValueString(self, 1, '1')
diff --git a/lmfdb/lfunctions/Lfunctionutilities.py b/lmfdb/lfunctions/Lfunctionutilities.py
--- a/lmfdb/lfunctions/Lfunctionutilities.py
+++ b/lmfdb/lfunctions/Lfunctionutilities.py
@@ -704,6 +704,7 @@ def specialValueTriple(L, s, sLatex_analytic, sLatex_arithmetic):
             val = "not computed"
         else:
             val = L.sageLfunction.value(s)
+            logger.warning("a value of an L-function has been computed on the fly")
 
     if sLatex_arithmetic:
         lfunction_value_tex_arithmetic = L.texname_arithmetic.replace('s)',  sLatex_arithmetic + ')')


Test patch:
Repository: LMFDB/lmfdb

Issue:
Knowl breadcrumbs
The breadcrumbs for a knowl page such as http://beta.lmfdb.org/knowledge/show/g2c.discriminant  looks like 
Knowledge -> Discriminant...
It would be nice to have an intermediate breadcrumb, in this case 'g2c',  which linked to the same page as "up".


Discussion:

Resolving patch:
diff --git a/lmfdb/app.py b/lmfdb/app.py
--- a/lmfdb/app.py
+++ b/lmfdb/app.py
@@ -368,7 +368,7 @@ def citation():
 def citing():
     t = "How to Cite LMFDB"
     b = [("Citing the LMFDB", url_for("citation")), (t, url_for("citing"))]
-    return render_template(_single_knowl, title=t, kid='content.how-to-cite', body_class='', bread=b)
+    return render_template(_single_knowl, title=t, kid='content.how_to_cite', body_class='', bread=b)
 
 @app.route("/citation/citations")
 def citations():
diff --git a/lmfdb/characters/main.py b/lmfdb/characters/main.py
--- a/lmfdb/characters/main.py
+++ b/lmfdb/characters/main.py
@@ -154,7 +154,7 @@ def how_computed_page():
     info['bread'] = [ ('Characters',url_for(".render_characterNavigation")),
     ('Dirichlet', url_for(".render_Dirichletwebpage")), ('Source', '') ]
     info['learnmore'] = learn('source')
-    return render_template("single.html", kid='dq.character.dirichlet.source', **info)
+    return render_template("single.html", kid='rcs.cande.character.dirichlet', **info)
 
 @characters_page.route("/Reliability")
 def reliability():
diff --git a/lmfdb/knowledge/main.py b/lmfdb/knowledge/main.py
--- a/lmfdb/knowledge/main.py
+++ b/lmfdb/knowledge/main.py
@@ -389,7 +389,7 @@ def show(ID):
             can_delete = (current_user.is_admin() or current_user.get_id() == author)
             author_name = userdb.lookup(author)["full_name"]
             k.comments[i] = (cid, author_name, timestamp, can_delete)
-    b = get_bread([('%s' % title, url_for('.show', ID=ID))])
+    b = get_bread([(k.category, url_for('.index', category=k.category)), ('%s' % title, url_for('.show', ID=ID))])
 
     return render_template(u"knowl-show.html",
                            title=title,
@@ -787,9 +787,12 @@ def knowl_sort_key(knowl):
     #    knowl_qualities.append("in progress")
     if current_user.is_admin():
         knowl_qualities.append("deleted")
+    b = []
+    if cur_cat:
+        b = [(cur_cat, url_for('.index', category=cur_cat))]
     return render_template("knowl-index.html",
                            title="Knowledge Database",
-                           bread=get_bread(),
+                           bread=get_bread(b),
                            knowls=knowls,
                            search=search,
                            searchbox=searchbox(search, bool(search)),


Test patch:
Repository: LMFDB/lmfdb

Issue:
Problem with jsonb in insert_many
Inserting a record with a jsonb column whose content looks like it contains an array can cause problems.  To reproduced a specific example:

```
sage: db.create_table_like("g2c_test","g2c_curves")
Table g2c_test created in 0.186 secs
sage: r=db.g2c_curves.lookup("2916.b.11664.1")
sage: db.g2c_test.insert_many([r])
---------------------------------------------------------------------------
DataError                                 Traceback (most recent call last)
<ipython-input-17-f60c5a3ae980> in <module>()
----> 1 db.g2c_test.insert_many([r])

/home/drew/github/lmfdb/lmfdb/backend/database.pyc in insert_many(self, data, resort, reindex, restat, commit)
   2598                 inserter = inserter.format(Identifier(table),
   2599                                            SQL(", ").join(map(Identifier, L[0].keys())))
-> 2600                 self._execute(inserter, L, values_list=True, template=template)
   2601             print "Inserted %s records into %s in %.3f secs"%(len(search_data), self.search_table, time.time()-now)
   2602             self._break_order()

/home/drew/github/lmfdb/lmfdb/backend/database.pyc in _execute(self, query, values, silent, values_list, template, commit, slow_note, reissued)
    358                 if template is not None:
    359                     template = template.as_string(self.conn)
--> 360                 execute_values(cur, query.as_string(self.conn), values, template)
    361             else:
    362                 try:

/scratch/sage/sage-8.3/local/lib/python2.7/site-packages/psycopg2/extras.pyc in execute_values(cur, sql, argslist, template, page_size)
   1275             parts.append(b',')
   1276         parts[-1:] = post
-> 1277         cur.execute(b''.join(parts))
   1278 
   1279 

DataError: malformed array literal: "6.0.186624.1"
LINE 1: ...e, '[[2,[1,0,2]],[3,[1]]]', true, '2916.b', ARRAY['6.0.18662...
                                                             ^
DETAIL:  Array value must start with "{" or dimension information.

```



Discussion:
Currently J.C. and I wrap those objects in Json (after importing Json from lmfdb.backend.encoding), and that workaround seems to work.

Resolving patch:
diff --git a/lmfdb/backend/database.py b/lmfdb/backend/database.py
--- a/lmfdb/backend/database.py
+++ b/lmfdb/backend/database.py
@@ -2577,7 +2577,7 @@ def insert_many(self, data, resort=True, reindex=False, restat=True, commit=True
             if reindex:
                 self.drop_pkeys()
                 self.drop_indexes()
-            jsonb_cols = [col for col, typ in self.col_type.iteritems() if typ == 'jsob']
+            jsonb_cols = [col for col, typ in self.col_type.iteritems() if typ == 'jsonb']
             for i, SD in enumerate(search_data):
                 SD["id"] = self.max_id() + i + 1
                 for col in jsonb_cols:


Test patch:
Repository: LMFDB/lmfdb

Issue:
Favicon color should be updated
If we are changing the color scheme, the background color of the favicon (small image that appears on a tab) should be updated to match.


Discussion:

Resolving patch:
diff --git a/lmfdb/utils/config.py b/lmfdb/utils/config.py
--- a/lmfdb/utils/config.py
+++ b/lmfdb/utils/config.py
@@ -44,7 +44,7 @@ def __init__(self, writeargstofile = False):
             dest = 'core_color',
             metavar = "COLOR",
             help = 'color template (see lmfdb/utils/color.py)',
-            default = 0,
+            default = 19,
             type = int)
 
         parser.add_argument('-p','--port',


Test patch:
Repository: LMFDB/lmfdb

Issue:
Could not download the elliptic curves of norm conductor 1
From the feedback page:

I could not download the elliptic curves of norm conductor 1 into a magma file.

Please respond to brumer@fordham.edu


Discussion:

Resolving patch:
diff --git a/lmfdb/ecnf/main.py b/lmfdb/ecnf/main.py
--- a/lmfdb/ecnf/main.py
+++ b/lmfdb/ecnf/main.py
@@ -378,7 +378,7 @@ def show_ecnf(nf, conductor_label, class_label, number):
                            learnmore=learnmore_list())
 
 def download_search(info):
-    dltype = info['submit']
+    dltype = info['Submit']
     delim = 'bracket'
     com = r'\\'  # single line comment start
     com1 = ''  # multiline comment start


Test patch:
Repository: LMFDB/lmfdb

Issue:
Server error on knowl regex search
Regex knowl searches that being with an asterix throw a server error:

http://www.lmfdb.org/knowledge/?search=*&regex=on




Discussion:

Resolving patch:
diff --git a/lmfdb/backend/database.py b/lmfdb/backend/database.py
--- a/lmfdb/backend/database.py
+++ b/lmfdb/backend/database.py
@@ -31,7 +31,7 @@
 import csv
 import sys
 
-from psycopg2 import connect, DatabaseError, InterfaceError, OperationalError, ProgrammingError, NotSupportedError
+from psycopg2 import connect, DatabaseError, InterfaceError, OperationalError, ProgrammingError, NotSupportedError, DataError
 from psycopg2.sql import SQL, Identifier, Placeholder, Literal, Composable
 from psycopg2.extras import execute_values
 from psycopg2.extensions import cursor as pg_cursor
@@ -380,7 +380,7 @@ def _execute(self, query, values=None, silent=None, values_list=False,
             else:
                 try:
                     cur.execute(query, values)
-                except (OperationalError, ProgrammingError, NotSupportedError) as e:
+                except (OperationalError, ProgrammingError, NotSupportedError, DataError) as e:
                     try:
                         context = ' happens while executing {}'.format(cur.mogrify(query, values))
                     except Exception:
diff --git a/lmfdb/knowledge/main.py b/lmfdb/knowledge/main.py
--- a/lmfdb/knowledge/main.py
+++ b/lmfdb/knowledge/main.py
@@ -28,7 +28,7 @@
 import markdown
 from lmfdb.knowledge import logger
 from lmfdb.utils import datetime_to_timestamp_in_ms,\
-                        timestamp_in_ms_to_datetime
+                        timestamp_in_ms_to_datetime, flash_error
 
 #ejust for those, who still use an older markdown
 try:
@@ -195,7 +195,7 @@ def ref_to_link(txt):
                 ans += ", "
             ans += this_link
 
-    return '[' + ans + ']' + " " + everythingelse
+    return '[' + ans + ']'  + everythingelse
 
 def md_latex_accents(text):
     """
@@ -757,9 +757,9 @@ def render_knowl(ID, footer=None, kwargs=None,
 
 @knowledge_page.route("/", methods=['GET', 'POST'])
 def index():
+    from psycopg2 import DataError
     cur_cat = request.args.get("category", "")
 
-
     filtermode = request.args.get("filtered")
     from knowl import knowl_status_code, knowl_type_code
     if request.method == 'POST':
@@ -780,7 +780,14 @@ def index():
     search = request.args.get("search", "")
     regex = (request.args.get("regex", "") == "on")
     keywords = search if regex else search.lower()
-    knowls = knowldb.search(category=cur_cat, filters=filters, types=types, keywords=keywords, regex=regex)
+    try:
+        knowls = knowldb.search(category=cur_cat, filters=filters, types=types, keywords=keywords, regex=regex)
+    except DataError as e:
+        knowls = {}
+        if regex and "invalid regular expression" in str(e):
+	    flash_error("The string %s is not a valid regular expression", keywords)
+        else:
+            flash_error("Unexpected error %s occured during knowl search", str(e))
 
     def first_char(k):
         t = k['title']


Test patch:
Repository: LMFDB/lmfdb

Issue:
Odd error from upsert in backend
I'm trying to use the upsert to change records that contain Jsonb fields, but SQL query construction is broken. Example:

```
sage: rec_find = json.loads('{"db_id":14, "name":"fields_human"}')
sage: rec_set = json.loads('{"nice_name":"fields_human", "NOTES":null, "INFO":nu
....: ll}')
sage: lmfdb.db['inv_tables'].upsert(rec_find, rec_set)
```
```
ProgrammingError: syntax error at or near "{"
LINE 1: INSERT INTO {0} ({1}) VALUES ({2}) RETURNING *
                    ^
 happens while executing INSERT INTO {0} ({1}) VALUES ({2}) RETURNING *
```

Any ideas?


Discussion:

Resolving patch:
diff --git a/lmfdb/backend/database.py b/lmfdb/backend/database.py
--- a/lmfdb/backend/database.py
+++ b/lmfdb/backend/database.py
@@ -2779,7 +2779,7 @@ def upsert(self, query, data, commit=True):
             if col != "id" and col not in self._search_cols:
                 raise ValueError("%s is not a column of %s"%(col, self.search_table))
         if self.extra_table is None:
-            search_data = data
+            search_data = dict(data)
             for col in data:
                 if col not in self._search_cols:
                     raise ValueError("%s is not a column of %s"%(col, self.search_table))
@@ -2823,7 +2823,8 @@ def upsert(self, query, data, commit=True):
                     self._execute(updater, dvalues)
                 if not self._out_of_order and any(key in self._sort_keys for key in data):
                     self._break_order()
-            else: # insertion
+
+            else:  # insertion
                 if "id" in data or "id" in query:
                     raise ValueError("Cannot specify an id for insertion")
                 new_row = True
@@ -2838,8 +2839,8 @@ def upsert(self, query, data, commit=True):
                 if self.extra_table is not None:
                     extras_data["id"] = self.max_id() + 1
                 for table, dat in cases:
-                    inserter = SQL("INSERT INTO {0} ({1}) VALUES ({2})")
-                    inserter.format(Identifier(table),
+                    inserter = SQL("INSERT INTO {0} ({1}) VALUES ({2})").format(
+                                    Identifier(table),
                                     SQL(", ").join(map(Identifier, dat.keys())),
                                     SQL(", ").join(Placeholder() * len(dat)))
                     self._execute(inserter, self._parse_values(dat))


Test patch:
Repository: LMFDB/lmfdb

Issue:
Allow search on rational j-invariant for ecnf
And fix a server error for the same pages. Fixes #3558

Compare the pages
https://beta.lmfdb.org/EllipticCurve/?start=50&hst=List&jinv=1728
after this change 
  /EllipticCurve/?start=50&hst=List&jinv=1728
will show a list of 911 curves with j-invariant 1728 defined over various fields, one can then exclude the base changed ones to get a list of all non-rational twists of these curves in the lmfdb.


Allow search on rational j-invariant for ecnf
And fix a server error for the same pages. Fixes #3558

Compare the pages
https://beta.lmfdb.org/EllipticCurve/?start=50&hst=List&jinv=1728
after this change 
  /EllipticCurve/?start=50&hst=List&jinv=1728
will show a list of 911 curves with j-invariant 1728 defined over various fields, one can then exclude the base changed ones to get a list of all non-rational twists of these curves in the lmfdb.




Discussion:

Resolving patch:
diff --git a/lmfdb/backend/database.py b/lmfdb/backend/database.py
--- a/lmfdb/backend/database.py
+++ b/lmfdb/backend/database.py
@@ -380,7 +380,7 @@ def _execute(self, query, values=None, silent=None, values_list=False,
             else:
                 try:
                     cur.execute(query, values)
-                except (OperationalError, ProgrammingError, NotSupportedError, DataError) as e:
+                except (OperationalError, ProgrammingError, NotSupportedError, DataError, SyntaxError) as e:
                     try:
                         context = ' happens while executing {}'.format(cur.mogrify(query, values))
                     except Exception:
@@ -2810,7 +2810,11 @@ def upsert(self, query, data, commit=True):
                 new_row = False
                 row_id = cur.fetchone()[0]
                 for table, dat in cases:
-                    if len(dat) == 1:
+                    # we are not updating any column in the extras table
+                    if len(dat) == 0:
+                        continue
+                    # the syntax for updating only one columns differs from multiple columns
+                    elif len(dat) == 1:
                         updater = SQL("UPDATE {0} SET {1} = {2} WHERE {3}")
                     else:
                         updater = SQL("UPDATE {0} SET ({1}) = ({2}) WHERE {3}")


Test patch:
Repository: LMFDB/lmfdb

Issue:
Allow search on rational j-invariant for ecnf
And fix a server error for the same pages. Fixes #3558

Compare the pages
https://beta.lmfdb.org/EllipticCurve/?start=50&hst=List&jinv=1728
after this change 
  /EllipticCurve/?start=50&hst=List&jinv=1728
will show a list of 911 curves with j-invariant 1728 defined over various fields, one can then exclude the base changed ones to get a list of all non-rational twists of these curves in the lmfdb.




Discussion:

Resolving patch:
diff --git a/lmfdb/backend/database.py b/lmfdb/backend/database.py
--- a/lmfdb/backend/database.py
+++ b/lmfdb/backend/database.py
@@ -380,7 +380,7 @@ def _execute(self, query, values=None, silent=None, values_list=False,
             else:
                 try:
                     cur.execute(query, values)
-                except (OperationalError, ProgrammingError, NotSupportedError, DataError) as e:
+                except (OperationalError, ProgrammingError, NotSupportedError, DataError, SyntaxError) as e:
                     try:
                         context = ' happens while executing {}'.format(cur.mogrify(query, values))
                     except Exception:
@@ -2810,7 +2810,11 @@ def upsert(self, query, data, commit=True):
                 new_row = False
                 row_id = cur.fetchone()[0]
                 for table, dat in cases:
-                    if len(dat) == 1:
+                    # we are not updating any column in the extras table
+                    if len(dat) == 0:
+                        continue
+                    # the syntax for updating only one columns differs from multiple columns
+                    elif len(dat) == 1:
                         updater = SQL("UPDATE {0} SET {1} = {2} WHERE {3}")
                     else:
                         updater = SQL("UPDATE {0} SET ({1}) = ({2}) WHERE {3}")
diff --git a/lmfdb/number_fields/web_number_field.py b/lmfdb/number_fields/web_number_field.py
--- a/lmfdb/number_fields/web_number_field.py
+++ b/lmfdb/number_fields/web_number_field.py
@@ -407,11 +407,12 @@ def galois_sib_data(self):
             for s in sibcnts:
                 repcounts[s[0][0]] += s[1]
             gc = 0
-            if galord<24:
+            if galord<48:
                 del repcounts[galord]
                 if self.degree() < galord:
                     gc = 1 
-            repcounts[self.degree()] -= numae
+            if numae>0:
+                repcounts[self.degree()] -= numae
             if repcounts[self.degree()] == 0:
                 del repcounts[self.degree()]
             self._data['repdata'] = [repcounts, numae, gc]


Test patch:
Repository: LMFDB/lmfdb

Issue:
Dirichlet character search by label error message
If I search by label for 3329.z from the Dirichlet characters homepage http://lmfdb.xyz/Character/Dirichlet/ the error message is "Error: the value z is invalid. It should be a positive integer coprime to and no greater than the modulus 3329." this should be changed in the case to reflect the fact that searching by orbit label is fine, just that z is too far down the alphabet.


Discussion:

Resolving patch:
diff --git a/lmfdb/characters/main.py b/lmfdb/characters/main.py
--- a/lmfdb/characters/main.py
+++ b/lmfdb/characters/main.py
@@ -264,7 +264,11 @@ def render_Dirichletwebpage(modulus=None, number=None):
 
     number = label_to_number(modulus, number)
     if number == 0:
-        flash_error("the value %s is invalid. It should be a positive integer coprime to and no greater than the modulus %s.", args['number'], args['modulus'])
+        flash_error(
+            "the value %s is invalid. It should either be a positive integer "
+            "coprime to and no greater than the modulus %s, or a letter that "
+            "corresponds to a valid orbit index.", args['number'], args['modulus']
+        )
         return redirect(url_for(".render_Dirichletwebpage"))
     args['number'] = number
     webchar = make_webchar(args)


Test patch: