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

Issue:
Problem with knowls in developer versions
If a developer is running their own copy of lmfdb and clicks on a knowl which doesn't exit yet, it crashes on a permissions error.  Recently, this would be ok, although trying to create the knowl would fail silently.  

Crashing seems like the wrong behavior. 



Discussion:

Resolving patch:
diff --git a/lmfdb/knowledge/knowl.py b/lmfdb/knowledge/knowl.py
--- a/lmfdb/knowledge/knowl.py
+++ b/lmfdb/knowledge/knowl.py
@@ -67,14 +67,17 @@ def get_history(limit=25):
 def is_locked(knowlid, delta_min=10):
     """
     returns a lock (as True), if there has been a lock in the last @delta_min minutes; else False.
-    attention, it discardes all locks prior to @delta_min!
+    attention, it discards all locks prior to @delta_min!
     """
     from datetime import datetime, timedelta
     now = datetime.utcnow()
     tdelta = timedelta(minutes=delta_min)
     time = now - tdelta
     history = getDBConnection().knowledge.history
+    #try:
     history.remove({'state': 'locked', 'time': {'$lt': time}})
+    #except:
+    #    return None 
     # search for both: either locked OR has been saved in the last 10 min
     lock = history.find_one({'_id': knowlid, 'time': {'$gte': time}})
     return lock or False
diff --git a/lmfdb/knowledge/main.py b/lmfdb/knowledge/main.py
--- a/lmfdb/knowledge/main.py
+++ b/lmfdb/knowledge/main.py
@@ -276,6 +276,7 @@ def test():
 @knowledge_page.route("/edit/<ID>")
 @login_required
 def edit(ID):
+    from pymongo.errors import OperationFailure 
     if not allowed_knowl_id.match(ID):
         flask.flash("""Oops, knowl id '%s' is not allowed.
                   It must consist of lowercase characters,
@@ -286,12 +287,20 @@ def edit(ID):
     from knowl import is_locked, set_locked
     lock = False
     if request.args.get("lock", "") != 'ignore':
-        lock = is_locked(knowl.id)
+        try:
+            lock = is_locked(knowl.id)
+        except OperationFailure as e:
+            logger.info("Oops, failed to get the lock. Error: %s" %e)
+            pass;
     # lock, if either lock is false or (lock is active), current user is editing again
     author_edits = lock and lock['who'] == current_user.get_id()
     logger.debug(author_edits)
     if not lock or author_edits:
-        set_locked(knowl, current_user.get_id())
+        try:
+            set_locked(knowl, current_user.get_id())
+        except OperationFailure as e:
+            logger.info("Oops, failed to set the lock. Error: %s" %e)
+            pass;
     if author_edits:
         lock = False
 


Test patch:
Repository: LMFDB/lmfdb

Issue:
Can't add new accounts
We can't assign new accounts (for editing knowls) because that has to be done on beta, not www.

I think this just involves changing line 28 of lmfdb/users/main.py
from
base_url = "http://www.l-functions.org"
to
base_url = "http://beta.lmfdb.org"

But I didn't want to do that in case it has a bad side-effect.



Discussion:
I will make that change and push to beta -- the change cannot be tested locally since clicking on RegisterTokens fails there.


Resolving patch:
diff --git a/lmfdb/users/main.py b/lmfdb/users/main.py
--- a/lmfdb/users/main.py
+++ b/lmfdb/users/main.py
@@ -24,11 +24,7 @@
 import pwdmanager
 from pwdmanager import LmfdbUser, LmfdbAnonymousUser
 
-# TODO update this url, needed for the user login token
-base_url = "http://www.l-functions.org"
-# TODO: Not sure this should be changed from l-functions -> lmfdb, because
-# I don't really understand how this is used. Paul
-
+base_url = "http://beta.lmfdb.org"
 
 @login_manager.user_loader
 def load_user(userid):


Test patch:
Repository: LMFDB/lmfdb

Issue:
sort number fields on download
On lmfdb-support, Alex Bartel pointed out

"If I download a file containing a list of number fields, then the entries are sorted in a weird way. The concrete example that I caught occurs if you press the MAGMA button on this page: http://beta.lmfdb.org/NumberField/?degree=4&signature=&discriminant=&galois_group=C4&ur_primes=&ram_quantifier=some&ram_primes=&class_number=&class_group=&count=20&search=Search"

and he is right.  Sorting of the search result cursor "res" happens in line 490 while the download test happens right before that (in number_fields_number_field.py).  That should change, and simply moving the sort function up would appear to be all that is required.



Discussion:

Resolving patch:
diff --git a/lmfdb/number_fields/number_field.py b/lmfdb/number_fields/number_field.py
--- a/lmfdb/number_fields/number_field.py
+++ b/lmfdb/number_fields/number_field.py
@@ -484,11 +484,11 @@ def number_field_search(**args):
     fields = C.numberfields.fields
 
     res = fields.find(query)
+    res = res.sort([('degree', ASC), ('disc_abs_key', ASC),('disc_sign', ASC)])
 
     if 'download' in info and info['download'] != '0':
         return download_search(info, res)
 
-    res = res.sort([('degree', ASC), ('disc_abs_key', ASC),('disc_sign', ASC)])
     nres = res.count()
     res = res.skip(start).limit(count)
 


Test patch:
Repository: LMFDB/lmfdb

Issue:
Server error on two Maass form pages
See http://www.lmfdb.org/ModularForm/GL2/Q/Maass/4f4bf90788aece438d000014.
and http://www/lmfdb.org/ModularForm/GL2/Q/Maass/4f4bf90788aece438d000016

Traceback:

Traceback (most recent call last):
  File "/usr/local/sage/sage-1/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/sage/sage-1/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/sage/sage-1/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/sage/sage-1/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/sage/sage-1/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/drew/github/lmfdb/lmfdb/modular_forms/maass_forms/maass_waveforms/views/mwf_main.py", line 169, in render_one_maass_waveform
    return render_one_maass_waveform_wp(info)
  File "/home/drew/github/lmfdb/lmfdb/modular_forms/maass_forms/maass_waveforms/views/mwf_main.py", line 260, in render_one_maass_waveform_wp
    info['MF'].set_table()
  File "/home/drew/github/lmfdb/lmfdb/modular_forms/maass_forms/maass_waveforms/backend/mwf_classes.py", line 320, in set_table
    c = ((self.coeffs.get(j, {})).get(0, None)).get(n, None)
AttributeError: 'NoneType' object has no attribute 'get'



Discussion:

Resolving patch:
diff --git a/lmfdb/modular_forms/maass_forms/maass_waveforms/backend/mwf_classes.py b/lmfdb/modular_forms/maass_forms/maass_waveforms/backend/mwf_classes.py
--- a/lmfdb/modular_forms/maass_forms/maass_waveforms/backend/mwf_classes.py
+++ b/lmfdb/modular_forms/maass_forms/maass_waveforms/backend/mwf_classes.py
@@ -317,7 +317,7 @@ def set_table(self, fnr=-1, cusp=0):
                             row.append(pretty_coeff(c))
                     else:
                         for j in range(self.dim):
-                            c = ((self.coeffs.get(j, {})).get(0, None)).get(n, None)
+                            c = ((self.coeffs.get(j, {})).get(0, {})).get(n, None)
                             if c is not None:
                                 row.append(pretty_coeff(c))
                                 realnumc += 1


Test patch:
Repository: LMFDB/lmfdb

Issue:
The meta description is a knowl
**_1 Upvote**_ Hello,

This line:
`
<meta name="description" content="Welcome to the LMFDB, the database of L-functions, modular forms, and related objects. These pages are intended to be a modern handbook including tables, formulas, links, and references for L-functions and their underlying objects.">
`
common to all the webpages, comes from this knowl:

http://beta.lmfdb.org/knowledge/show/intro.description

see: https://github.com/LMFDB/lmfdb/blob/master/lmfdb/base.py#L203

Shouldn't this be hardcoded?

Best,
Edgar



Discussion:
+1 Anyone who can log in on beta (which is not secure, we are not even using https) can change our welcome message say whatever they want it to say.  This should definitely be hard-coded.


Resolving patch:
diff --git a/lmfdb/base.py b/lmfdb/base.py
--- a/lmfdb/base.py
+++ b/lmfdb/base.py
@@ -33,8 +33,9 @@ def get_logfocus():
 # getDBConnection() and should always be obtained from that)
 _C = None
 
+#FIXME perhaps the globals dbport and DEFAULT_DB_PORT should be removed?
+#we could had it a default argument to makeDBConnection
 DEFAULT_DB_PORT = 37010
-#FIXME perhaps the global dbport removed
 dbport = DEFAULT_DB_PORT
 
 
@@ -200,7 +201,7 @@ def ctx_proc_userdata():
 
     # meta_description appears in the meta tag "description"
     import knowledge
-    vars['meta_description'] = knowledge.knowl.Knowl("intro.description").content
+    vars['meta_description'] = r'Welcome to the LMFDB, the database of L-functions, modular forms, and related objects. These pages are intended to be a modern handbook including tables, formulas, links, and references for L-functions and their underlying objects.'
     vars['shortthanks'] = r'This project is supported by <a href="%s">grants</a> from the US National Science Foundation and the UK Engineering and Physical Sciences Research Council.' % (url_for('acknowledgment') + "#sponsors")
 #    vars['feedbackpage'] = url_for('contact')
     vars['feedbackpage'] = r"https://docs.google.com/spreadsheet/viewform?formkey=dDJXYXBleU1BMTFERFFIdjVXVmJqdlE6MQ"


Test patch:
Repository: LMFDB/lmfdb

Issue:
Typo in genus 2 decomposition
See:
  http://lmfdb.org/Genus2Curve/Q/900601/a/900601/1

At the bottom, the polynomial is not formatted correctly.  Not sure if this is a one-off (in which case I can quickly fix it), or if it occurs in other cases.



Discussion:

Resolving patch:
diff --git a/lmfdb/genus2_curves/web_g2c.py b/lmfdb/genus2_curves/web_g2c.py
--- a/lmfdb/genus2_curves/web_g2c.py
+++ b/lmfdb/genus2_curves/web_g2c.py
@@ -433,7 +433,7 @@ def split_field_statement(is_simple_geom, field_label, poly):
         return """Splits over the number field \(\Q (b) \simeq \) <a href=%s>%s</a> with defining polynomial:<br>&nbsp;&nbsp;\(%s\)"""\
             % (url, pretty, poly)
     else:
-        return """Splits over the number field \(\Q (b)\) with defining polynomialL<br>&nbsp;&nbsp%s""" % poly
+        return """Splits over the number field \(\Q (b)\) with defining polynomial:<br>&nbsp;&nbsp;\(%s\)""" % poly
 
 def split_statement(coeffs, labels, condnorms):
     if len(coeffs) == 1:


Test patch:
Repository: LMFDB/lmfdb

Issue:
alpha / a mixup in q-expansions
As reported via the bug tracker:

"Not at all a serious problem, but a curious issue:

When looking at Fourier expansions of modular forms with coefficients in a number field, the number field is given as Q(alpha), and the initial q-expansion involves alpha, but for some reason when you click on "show more coefficients", the alpha's become a's."

For example

http://www.lmfdb.org/ModularForm/GL2/Q/holomorphic/23/2/1/a/



Discussion:
I can fix this by changing 'a' to '\alpha ' on line 223 of emf_main.py and will make a pull request, but someone who has worked on the display of these q-expansions should make sure that this is not going to have adverse side-effects.


Resolving patch:
diff --git a/lmfdb/modular_forms/elliptic_modular_forms/views/emf_main.py b/lmfdb/modular_forms/elliptic_modular_forms/views/emf_main.py
--- a/lmfdb/modular_forms/elliptic_modular_forms/views/emf_main.py
+++ b/lmfdb/modular_forms/elliptic_modular_forms/views/emf_main.py
@@ -220,7 +220,7 @@ def get_qexp(level, weight, character, label, prec, latex=False, **kwds):
         if not latex:
             c = WNF.q_expansion
         else:
-            c = WNF.q_expansion_latex(prec=prec, name = 'a')
+            c = WNF.q_expansion_latex(prec=prec, name = '\\alpha ')
         return c
     except Exception as e:
         return "<span style='color:red;'>ERROR: %s</span>" % e.message


Test patch:
Repository: LMFDB/lmfdb

Issue:
Quotation marks 
The latex use of `` and " don't render correctly. For example see
http://www.lmfdb.org/L/history just below the header Riemann's Memoir.



Discussion:
The "correct" LaTeX way is to use single quotes on both ends:
``like this.''

It is relatively easy to convert the correct markup.  But if a document
(like a knowl) is edited by several people, then some may do "this"
and others may do `that'' and yet others will do`something else."

It is almost impossible to automatically convert a document which
simultaneously contains all three versions.

Would it be adequate to only support the ``officially correct'' way?

On Tue, 10 May 2016, brianconrey wrote:

> The latex use of `` and " don't render correctly. For example see
> http://www.lmfdb.org/L/history just below the header Riemann's Memoir.
> 
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly or view it on
> GitHub[AAM6LHJKHgCLaH2HIcUvqo19_oiHFoB9ks5qAQnugaJpZM4IblJb.gif]

> Would it be adequate to only support the ``officially correct'' way?

Yes.

> On Tue, 10 May 2016, brianconrey wrote:
> 
> > The latex use of `` and " don't render correctly. For example see
> > http://www.lmfdb.org/L/history just below the header Riemann's Memoir.
> > 
> > ?
> > You are receiving this because you are subscribed to this thread.
> > Reply to this email directly or view it on
> > GitHub[AAM6LHJKHgCLaH2HIcUvqo19_oiHFoB9ks5qAQnugaJpZM4IblJb.gif]
> 
> ?
> You are receiving this because you authored the thread.
> Reply to this email directly or view it on
> GitHub[ABa5BKYopka7OsMQiOjoDEdjxBRJopCtks5qAQtFgaJpZM4IblJb.gif]


Resolving patch:
diff --git a/lmfdb/knowledge/main.py b/lmfdb/knowledge/main.py
--- a/lmfdb/knowledge/main.py
+++ b/lmfdb/knowledge/main.py
@@ -192,6 +192,7 @@ def md_latex_accents(text):
     knowl_content = re.sub(r"\\'{([a-zA-Z])}",r"&\1acute;",knowl_content)
     knowl_content = re.sub(r"\\`([a-zA-Z])",r"&\1grave;",knowl_content)
     knowl_content = re.sub(r"\\`{([a-zA-Z])}",r"&\1grave;",knowl_content)
+    knowl_content = re.sub(r"``(?P<a>[\S\s]*?)''", r"&ldquo;\1&rdquo;", knowl_content)
 
     return knowl_content
 


Test patch:
Repository: LMFDB/lmfdb

Issue:
Internal server error on ecnf j-invariant search
If you go to http://www.lmfdb.org/EllipticCurve/2.2.5.1/ and type invalid data into the j-invariant box (e.g. "garbage" or even "phi+1") you get a server error:

http://www.lmfdb.org/EllipticCurve/2.2.5.1/?start=0&count=50&field=2.2.5.1&conductor_norm=&include_isogenous=on&include_base_change=on&include_Q_curves=include&include_cm=include&torsion=&torsion_structure=&jinv=garbage

This is caused by the try/except in elliptic_curve_search catching ValueError but not TypeError.  I will fix this, and for the fields 2.2.5.1 and 2.0.4.1, convert phi to a and i to a (respectively).



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
@@ -369,6 +369,11 @@ def elliptic_curve_search(info):
 
     query = {}
 
+    if 'jinv' in info:
+        if info.get('field','').strip() == '2.2.5.1':
+            info['jinv'] = info['jinv'].replace('phi','a')
+        if info.get('field','').strip() == '2.0.4.1':
+            info['jinv'] = info['jinv'].replace('i','a')
     try:
         parse_ints(info,query,'conductor_norm')
         parse_noop(info,query,'conductor_label')
@@ -378,7 +383,7 @@ def elliptic_curve_search(info):
         parse_bracketed_posints(info,query,'torsion_structure',maxlength=2)
         if 'torsion_structure' in query and not 'torsion_order' in query:
             query['torsion_order'] = reduce(mul,[int(n) for n in query['torsion_structure']],1)
-    except ValueError:
+    except (TypeError,ValueError):
         return search_input_error(info, bread)
         
     if query.get('field_label') == '1.1.1.1':


Test patch:
Repository: LMFDB/lmfdb

Issue:
Tweak to gp code for elliptic curves over number fields
With reference to (for example) http://www.lmfdb.org/EllipticCurve/3.3.148.1/356.1/a/1 Bill Allombert suggests that instead of
K = nfinit(x^3 - x^2 - 3_x + 1); a=x
we put
K = nfinit(a^3 - a^2 - 3_a + 1);

Possibly also relevant for number field code snippets.



Discussion:

Resolving patch:
diff --git a/lmfdb/ecnf/WebEllipticCurve.py b/lmfdb/ecnf/WebEllipticCurve.py
--- a/lmfdb/ecnf/WebEllipticCurve.py
+++ b/lmfdb/ecnf/WebEllipticCurve.py
@@ -505,10 +505,10 @@ def make_code_snippets(self):
 
         gen = self.field.generator_name().replace("\\","") # phi not \phi
         for lang in ['sage', 'magma', 'pari']:
-            self._code['field'][lang] = self._code['field'][lang] % self.field.poly()
-            if gen != 'a':
-                self._code['field'][lang] = self._code['field'][lang].replace("<a>","<%s>" % gen)
-                self._code['field'][lang] = self._code['field'][lang].replace("a=","%s=" % gen)
+            pol = str(self.field.poly())
+            if lang=='pari':
+                pol = pol.replace('x',gen)
+            self._code['field'][lang] = (self._code['field'][lang] % pol).replace("<a>", "<%s>" % gen)
 
         for lang in ['sage', 'magma', 'pari']:
             self._code['curve'][lang] = self._code['curve'][lang] % self.ainvs


Test patch:
Repository: LMFDB/lmfdb

Issue:
hmf: large eigenvalue display when asking for more
In HMF pages, the large eigenvalues are not displayed. However, when one changes the number of eigenvalues to display (for instance to check for which primes there are Hecke eigenvalues in the DB), all the eigenvalues get displayed and the page takes a long time to render. Maybe we should also hide them in this case?

Example: /ModularForm/GL2/TotallyReal/3.3.321.1/holomorphic/3.3.321.1-293.1-b
hmf: large eigenvalue display when asking for more
In HMF pages, the large eigenvalues are not displayed. However, when one changes the number of eigenvalues to display (for instance to check for which primes there are Hecke eigenvalues in the DB), all the eigenvalues get displayed and the page takes a long time to render. Maybe we should also hide them in this case?

Example: /ModularForm/GL2/TotallyReal/3.3.321.1/holomorphic/3.3.321.1-293.1-b


Discussion:
This should probably also be labelled hmf.
This should probably also be labelled hmf.

Resolving patch:
diff --git a/lmfdb/hilbert_modular_forms/hilbert_modular_form.py b/lmfdb/hilbert_modular_forms/hilbert_modular_form.py
--- a/lmfdb/hilbert_modular_forms/hilbert_modular_form.py
+++ b/lmfdb/hilbert_modular_forms/hilbert_modular_form.py
@@ -296,6 +296,7 @@ def render_hmf_webpage(**args):
         numeigs = int(numeigs)
     except:
         numeigs = 20
+    info['numeigs'] = numeigs
 
     hmf_field = C.hmfs.fields.find_one({'label': data['field_label']})
     gen_name = findvar(hmf_field['ideals'])
@@ -357,9 +358,6 @@ def render_hmf_webpage(**args):
     except KeyError:
         display_eigs = False
 
-    if 'numeigs' in request.args:
-        display_eigs = True
-
     info['hecke_polynomial'] = teXify_pol(info['hecke_polynomial'])
 
     if 'AL_eigenvalues_fixed' in data:
@@ -375,6 +373,7 @@ def render_hmf_webpage(**args):
 
     max_eig_len = max([len(eig['eigenvalue']) for eig in info['eigs']])
     display_eigs = display_eigs or (max_eig_len<=300)
+    info['display_eigs'] = display_eigs
     if not display_eigs:
         for eig in info['eigs']:
             if len(eig['eigenvalue']) > 300:


Test patch:
Repository: LMFDB/lmfdb

Issue:
Line up eigenvalues on Hilbert modular forms pages
On Hilbert modular forms pages (like [this random one](http://beta.lmfdb.org/ModularForm/GL2/TotallyReal/6.6.1229312.1/holomorphic/6.6.1229312.1-169.1-b)), the column containing the coefficients appears ragged since some entries have minus signs and others don't. We could make it not appear ragged if we inserted the space for a minus sign on each row without it.




Discussion:

Resolving patch:
diff --git a/lmfdb/hilbert_modular_forms/hilbert_modular_form.py b/lmfdb/hilbert_modular_forms/hilbert_modular_form.py
--- a/lmfdb/hilbert_modular_forms/hilbert_modular_form.py
+++ b/lmfdb/hilbert_modular_forms/hilbert_modular_form.py
@@ -18,6 +18,7 @@
 from lmfdb.utils import to_dict, random_value_from_collection, web_latex_split_on_pm
 from lmfdb.search_parsing import parse_nf_string, parse_ints, parse_hmf_weight, parse_count, parse_start
 
+
 def db_forms():
     hmfs = getDBConnection().hmfs
     return hmfs.forms
@@ -81,6 +82,20 @@ def teXify_pol(pol_str):  # TeXify a polynomial (or other string containing poly
 
     return o_str
 
+def add_space_if_positive(texified_pol):
+    """
+    Add a space if texified_pol is positive to match alignment of positive and
+    negative coefficients.
+
+    Examples:
+    >>> add_space_if_positive('1')
+    '\phantom{-}1'
+    >>> add_space_if_positive('-1')
+    '-1'
+    """
+    if texified_pol[0] == '-':
+        return texified_pol
+    return "\phantom{-}" + texified_pol
 
 @hmf_page.route("/")
 def hilbert_modular_form_render_webpage():
@@ -145,19 +160,19 @@ def hilbert_modular_form_search(**args):
         parse_hmf_weight(info,query,'weight',qfield=('parallel_weight','weight'))
     except ValueError:
         return search_input_error()
-        
+
     if 'cm' in info:
         if info['cm'] == 'exclude':
             query['is_CM'] = 'no'
         elif info['cm'] == 'only':
             query['is_CM'] = 'yes'
-                
+
     if 'bc' in info:
         if info['bc'] == 'exclude':
             query['is_base_change'] = 'no'
         elif info['bc'] == 'only':
             query['is_base_change'] = 'yes'
-                     
+
     count = parse_count(info,100)
     start = parse_start(info)
 
@@ -396,7 +411,7 @@ def render_hmf_webpage(**args):
 
     primes = hmf_field['primes']
     n = min(len(eigs), len(primes))
-    info['eigs'] = [{'eigenvalue': teXify_pol(eigs[i]),
+    info['eigs'] = [{'eigenvalue': add_space_if_positive(teXify_pol(eigs[i])),
                      'prime_ideal': teXify_pol(primes[i]),
                      'prime_norm': primes[i][1:primes[i].index(',')]} for i in range(n)]
 


Test patch: