Repository: LMFDB/lmfdb

Issue:
Server error on subgroup page
From the flasklog. https://beta.lmfdb.org/Groups/Abstract/sub/1024.ec.2.i1 throws a server error trying to factor 0:

```
Exception on /Groups/Abstract/sub/1024.ec.2.i1 [GET]
Traceback (most recent call last):
  File "/home/sage/sage-9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/sage/sage-9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/sage/sage-9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/sage/sage-9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/home/lmfdb/lmfdb-git-dev/lmfdb/groups/abstract/main.py", line 765, in by_subgroup_label
    return render_abstract_subgroup(label)
  File "/home/lmfdb/lmfdb-git-dev/lmfdb/groups/abstract/main.py", line 1511, in render_abstract_subgroup
    return render_template(
  File "/home/sage/sage-9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/flask/templating.py", line 147, in render_template
    return _render(app, template, context)
  File "/home/sage/sage-9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/flask/templating.py", line 130, in _render
    rv = template.render(context)
  File "/home/sage/sage-9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/home/sage/sage-9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/home/lmfdb/lmfdb-git-dev/lmfdb/groups/abstract/templates/abstract-show-subgroup.html", line 1, in top-level template code
    {% extends "homepage.html" %}
  File "/home/lmfdb/lmfdb-git-dev/lmfdb/templates/homepage.html", line 19, in top-level template code
    <div class="{{ [L,'nodisplay','code','codebox'] | join(' ')}}">{% for line in lines %}{% if lines | length == 1 %}{{prompt}}:&nbsp;{% endif %}{{line}}<br /><div style="margin: 0; padding: 0; height: 0;">&nbsp;</div>{# this div is a workaround for a copy-tex bug where if a code block followed a hidden code block followed by math was selected and copied the hidden block would be also it is important that it has display: block #}{% endfor %}</div>
  File "/home/lmfdb/lmfdb-git-dev/lmfdb/templates/base.html", line 187, in top-level template code
    {% block body -%}{%- endblock body %}
  File "/home/lmfdb/lmfdb-git-dev/lmfdb/templates/homepage.html", line 246, in block 'body'
    {% block content -%}
  File "/home/lmfdb/lmfdb-git-dev/lmfdb/groups/abstract/templates/abstract-show-subgroup.html", line 164, in block 'content'
    {{seq.sub.show_aut_group()|safe}}
  File "/home/lmfdb/lmfdb-git-dev/lmfdb/groups/abstract/web_groups.py", line 2210, in show_aut_group
    return f'<a href="{url}">${group_names_pretty(self.aut_group)}$</a>, of order {pos_int_and_factor(self.aut_order)}'
  File "/home/lmfdb/lmfdb-git-dev/lmfdb/utils/web_display.py", line 243, in pos_int_and_factor
    factors = n.factor()
  File "sage/rings/integer.pyx", line 3919, in sage.rings.integer.Integer.factor
    raise ArithmeticError("factorization of 0 is not defined")
ArithmeticError: factorization of 0 is not defined
[2024-02-10 13:10:12 UTC] 500 error on URL https://beta.lmfdb.org/Groups/Abstract/sub/1024.ec.2.i1 ()
```


Discussion:

Resolving patch:
diff --git a/lmfdb/groups/abstract/main.py b/lmfdb/groups/abstract/main.py
--- a/lmfdb/groups/abstract/main.py
+++ b/lmfdb/groups/abstract/main.py
@@ -745,7 +745,7 @@ def by_abelian_label(label):
 def auto_gens(label):
     label = clean_input(label)
     gp = WebAbstractGroup(label)
-    if gp.is_null():
+    if gp.is_null() or gp.source == "Missing":  # latter is for groups in Magma but not GAP db
         flash_error("No group with label %s was found in the database.", label)
         return redirect(url_for(".index"))
     if gp.live() or gp.aut_gens is None:
@@ -774,7 +774,7 @@ def char_table(label):
     info = to_dict(request.args,
                    dispv=sparse_cyclotomic_to_mathml)
     gp = WebAbstractGroup(label)
-    if gp.is_null():
+    if gp.is_null() or gp.source == "Missing":  # latter is for groups not in GAP but in Magma db
         flash_error("No group with label %s was found in the database.", label)
         return redirect(url_for(".index"))
     if gp.live():
@@ -800,7 +800,7 @@ def Qchar_table(label):
     label = clean_input(label)
     info = to_dict(request.args, conv=integer_to_mathml)
     gp = WebAbstractGroup(label)
-    if gp.is_null():
+    if gp.is_null() or gp.source == "Missing": # latter is for groups not in GAP but in Magma db
         flash_error("No group with label %s was found in the database.", label)
         return redirect(url_for(".index"))
     if not gp.rational_characters_known:
@@ -821,7 +821,7 @@ def Qchar_table(label):
 def _subgroup_diagram(label, title, only, style):
     label = clean_input(label)
     gp = WebAbstractGroup(label)
-    if gp.is_null():
+    if gp.is_null() or gp.source == "Missing":  # latter is for groups in Magma but not in GAP db
         flash_error("No group with label %s was found in the database.", label)
         return redirect(url_for(".index"))
     dojs, display_opts = diagram_js_string(gp, only=only)
@@ -1362,7 +1362,7 @@ def render_abstract_group(label, data=None):
         gp = WebAbstractGroup(label)
     elif isinstance(data, list): # abelian group
         gp = WebAbstractGroup(label, data=data)
-    if gp.is_null():
+    if gp.is_null() or gp.source == "Missing": #groups of order 6561 are not in GAP but are labeled in Magma
         flash_error("No group with label %s was found in the database.", label)
         return redirect(url_for(".index"))
     # check if it fails to be a potential label even
@@ -1640,7 +1640,7 @@ def picture(label):
     if label_is_valid(label):
         label = clean_input(label)
         gp = WebAbstractGroup(label)
-        if gp.is_null():
+        if gp.is_null() or gp.source == "Missing": # latter is for groups in Magma but not GAP db
             flash_error("No group with label %s was found in the database.", label)
             return redirect(url_for(".index"))
         # The user specifically requested the image, so we don't impose a limit on the number of conjugacy classes
diff --git a/lmfdb/groups/abstract/web_groups.py b/lmfdb/groups/abstract/web_groups.py
--- a/lmfdb/groups/abstract/web_groups.py
+++ b/lmfdb/groups/abstract/web_groups.py
@@ -257,8 +257,7 @@ def __init__(self, label, data=None):
 
     # We support some basic information for groups not in the database using GAP
     def live(self):
-        # return not self.source == "db"
-        return self._data is not None and not isinstance(self._data, dict)
+        return self._data is not None and not isinstance(self._data, dict)  
 
     @lazy_attribute
     def G(self):
@@ -286,7 +285,10 @@ def G(self):
         if self.order == 1 or self.element_repr_type == "PC":  # trvial
             return self.PCG
         else:
-            gens = [self.decode(g) for g in self.representations[self.element_repr_type]["gens"]]
+            if self.element_repr_type == "Lie":   #need to take first entry of Lie type
+                gens = [self.decode(g) for g in self.representations[self.element_repr_type][0]["gens"]]
+            else:
+                gens = [self.decode(g) for g in self.representations[self.element_repr_type]["gens"]]
             return libgap.Group(gens)
 
     @lazy_attribute
@@ -2206,8 +2208,11 @@ def show_aut_group(self):
                 else:
                     return f"Group of order {pos_int_and_factor(self.aut_order)}"
             else:
-                url = url_for(".by_label", label=self.aut_group)
-                return f'<a href="{url}">${group_names_pretty(self.aut_group)}$</a>, of order {pos_int_and_factor(self.aut_order)}'
+                if self.aut_order is None:
+                    return r"not computed"
+                else:
+                    url = url_for(".by_label", label=self.aut_group)
+                    return f'<a href="{url}">${group_names_pretty(self.aut_group)}$</a>, of order {pos_int_and_factor(self.aut_order)}'
         except AssertionError:  # timed out
             return r"$\textrm{Computation timed out}$"
 


Test patch: