Repository: LMFDB/lmfdb

Issue:
Elliptic curves fail to handle some nonexistent fields
Note that https://www.lmfdb.org/EllipticCurve/banana/ works or https://www.lmfdb.org/EllipticCurve/2.2.4.1/,
but
https://www.lmfdb.org/EllipticCurve/4.4.10273.11/
raises an error:
```
Exception on /EllipticCurve/4.4.103273.11/ [GET]
Traceback (most recent call last):
  File "sage/misc/cachefunc.pyx", line 996, in sage.misc.cachefunc.CachedFunction.__call__ (build/cythonized/sage/misc/cachefunc.c:5975)
    return self.cache[k]
KeyError: (('4.4.103273.11',), ())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/lmfdb/lmfdb-git-web/lmfdb/ecnf/main.py", line 266, in show_ecnf1
    nf_label, nf_pretty = get_nf_info(nf)
  File "/home/lmfdb/lmfdb-git-web/lmfdb/ecnf/main.py", line 103, in get_nf_info
    pretty = field_pretty (label)
  File "sage/misc/cachefunc.pyx", line 1001, in sage.misc.cachefunc.CachedFunction.__call__ (build/cythonized/sage/misc/cachefunc.c:6101)
    w = self.f(*args, **kwds)
  File "/home/lmfdb/lmfdb-git-web/lmfdb/number_fields/web_number_field.py", line 226, in field_pretty
    subs = wnf.subfields()
  File "/home/lmfdb/lmfdb-git-web/lmfdb/number_fields/web_number_field.py", line 597, in subfields
    if not self.haskey('subfields'):
  File "/home/lmfdb/lmfdb-git-web/lmfdb/number_fields/web_number_field.py", line 487, in haskey
    return self._data.get(key) is not None
AttributeError: 'NoneType' object has no attribute 'get'
[2021-02-23 18:07:40 UTC] 500 error on URL https://www.lmfdb.org/EllipticCurve/4.4.103273.11/ ()
Exception on /EllipticCurve/4.4.10273.11/ [GET]
Traceback (most recent call last):
  File "sage/misc/cachefunc.pyx", line 996, in sage.misc.cachefunc.CachedFunction.__call__ (build/cythonized/sage/misc/cachefunc.c:5975)
    return self.cache[k]
KeyError: (('4.4.10273.11',), ())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/sage/sage-9.2/local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/lmfdb/lmfdb-git-web/lmfdb/ecnf/main.py", line 266, in show_ecnf1
    nf_label, nf_pretty = get_nf_info(nf)
  File "/home/lmfdb/lmfdb-git-web/lmfdb/ecnf/main.py", line 103, in get_nf_info
    pretty = field_pretty (label)
  File "sage/misc/cachefunc.pyx", line 1001, in sage.misc.cachefunc.CachedFunction.__call__ (build/cythonized/sage/misc/cachefunc.c:6101)
    w = self.f(*args, **kwds)
  File "/home/lmfdb/lmfdb-git-web/lmfdb/number_fields/web_number_field.py", line 226, in field_pretty
    subs = wnf.subfields()
  File "/home/lmfdb/lmfdb-git-web/lmfdb/number_fields/web_number_field.py", line 597, in subfields
    if not self.haskey('subfields'):
  File "/home/lmfdb/lmfdb-git-web/lmfdb/number_fields/web_number_field.py", line 487, in haskey
    return self._data.get(key) is not None
AttributeError: 'NoneType' object has no attribute 'get'
[2021-02-23 18:07:48 UTC] 500 error on URL https://www.lmfdb.org/EllipticCurve/4.4.10273.11/ ()
```


Discussion:

Resolving patch:
diff --git a/lmfdb/classical_modular_forms/main.py b/lmfdb/classical_modular_forms/main.py
--- a/lmfdb/classical_modular_forms/main.py
+++ b/lmfdb/classical_modular_forms/main.py
@@ -1604,14 +1604,13 @@ def main_array(self, info):
         if info is None:
             return self.browse_array
         search_type = info.get('search_type', info.get('hst', 'List'))
-        if search_type in ['List', 'Dimensions', 'Traces', 'DynStats']:
-            return self.refine_array
-        elif search_type in ['Spaces', 'SpaceTraces']:
+        if search_type in ['Spaces', 'SpaceTraces']:
             return self.space_array
         elif search_type == 'SpaceDimensions':
             return self.sd_array
         else:
-            raise ValueError
+            # search_type in ['List', 'Dimensions', 'Traces', 'DynStats']:
+            return self.refine_array
 
     def search_types(self, info):
         basic = [('List', 'List of forms'),
diff --git a/lmfdb/ecnf/main.py b/lmfdb/ecnf/main.py
--- a/lmfdb/ecnf/main.py
+++ b/lmfdb/ecnf/main.py
@@ -101,8 +101,8 @@ def get_nf_info(lab):
     try:
         label = nf_string_to_label(lab)
         pretty = field_pretty (label)
-    except ValueError:
-        raise ValueError(Markup("<span style='color:black'>%s</span> is not a valid number field label. %s" % escape(lab)))
+    except ValueError as err:
+        raise ValueError(Markup("<span style='color:black'>%s</span> is not a valid number field label. %s" % (escape(lab),err)))
     return label, pretty
 
 
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
@@ -484,7 +484,7 @@ def poly(self):
         return coeff_to_poly(self._data['coeffs'])
 
     def haskey(self, key):
-        return self._data.get(key) is not None
+        return self._data and self._data.get(key) is not None
 
     # Warning, this produces our preferred integral basis
     # But, if you have the sage number field do computations,


Test patch: