Skip to content

Handle Cardinality errors more gracefully #9

Description

@sjmf

@ItIsJordan can you take a look at the below stacktrace and see if there's anything we can do with better error handling?

Details
 gunicorn[359711]: 2025-08-12 15:45:42,213 django.template DEBUG    Exception while resolving variable 'name' in template 'unknown'.
 gunicorn[359711]: Traceback (most recent call last):
 gunicorn[359711]:   File "/opt/arches/HeritageBridge/ENV/lib/python3.9/site-packages/django/core/handlers/exception.py", line 35, in inner
 gunicorn[359711]:     response = get_response(request)
 gunicorn[359711]:   File "/opt/arches/HeritageBridge/ENV/lib/python3.9/site-packages/django/core/handlers/base.py", line 113, in _get_response
 gunicorn[359711]:     resolver_match = resolver.resolve(request.path_info)
 gunicorn[359711]:   File "/opt/arches/HeritageBridge/ENV/lib/python3.9/site-packages/django/urls/resolvers.py", line 527, in resolve
 gunicorn[359711]:     raise Resolver404({'tried': tried, 'path': new_path})
 gunicorn[359711]: django.urls.exceptions.Resolver404: {'tried': [[<URLResolver <URLPattern list> (admin:admin) 'admin/'>], [<URLPattern 'api/' [name='api_ref']>], [<URLPattern 'api/<str:model>/' [name='object-list']>], [<URLPattern 'api/<str:model>/<int:pk>/' [name='object-instance']>], [<URLPattern 'api/<str:model>/<uuid:pk>/' [name='object-instance']>], [<URLPattern 'api/login'>], [<URLPattern 'api/eamena/resources' [name='eamena-resource']>], [<URLPattern 'api/images/search' [name='image-search']>], [<URLPattern 'api/eamena/submit' [name='eamena-resource-image']>], [<URLPattern 'api-DEP/<str:model_name>/' [name='api_dispatch']>], [<URLPattern 'api-DEP/<str:model_name>/<int:id>/' [name='api_dispatch']>], [<URLPattern 'api-DEP/<str:model_name>/<uuid:id>/' [name='api_dispatch']>], [<URLResolver <module 'frontend.urls' from '/opt/arches/HeritageBridge/herbridge/frontend/urls.py'> (None:None) ''>, <URLPattern ''>], [<URLPattern '^media/(?P<path>.*)$'>]], 'path': 'undefined'}

 gunicorn[359711]: During handling of the above exception, another exception occurred:
 gunicorn[359711]: Traceback (most recent call last):
 gunicorn[359711]:   File "/opt/arches/HeritageBridge/ENV/lib/python3.9/site-packages/django/template/base.py", line 835, in _resolve_lookup
 gunicorn[359711]:     current = current[bit]
 gunicorn[359711]: TypeError: 'URLResolver' object is not subscriptable
 gunicorn[359711]: During handling of the above exception, another exception occurred:
 gunicorn[359711]: Traceback (most recent call last):
 gunicorn[359711]:   File "/opt/arches/HeritageBridge/ENV/lib/python3.9/site-packages/django/template/base.py", line 843, in _resolve_lookup
 gunicorn[359711]:     current = getattr(current, bit)
 gunicorn[359711]: AttributeError: 'URLResolver' object has no attribute 'name'
 gunicorn[359711]: During handling of the above exception, another exception occurred:
 gunicorn[359711]: Traceback (most recent call last):
 gunicorn[359711]:   File "/opt/arches/HeritageBridge/ENV/lib/python3.9/site-packages/django/template/base.py", line 849, in _resolve_lookup
 gunicorn[359711]:     current = current[int(bit)]
 gunicorn[359711]: ValueError: invalid literal for int() with base 10: 'name'
 gunicorn[359711]: During handling of the above exception, another exception occurred:
 gunicorn[359711]: Traceback (most recent call last):
 gunicorn[359711]:   File "/opt/arches/HeritageBridge/ENV/lib/python3.9/site-packages/django/template/base.py", line 854, in _resolve_lookup
 gunicorn[359711]:     raise VariableDoesNotExist("Failed lookup for key "
 gunicorn[359711]: django.template.base.VariableDoesNotExist: Failed lookup for key [name] in <URLResolver <URLPattern list> (admin:admin) 'admin/'>
 gunicorn[359711]: 2025-08-12 15:45:42,221 django.request WARNING  Not Found: /undefined
 
 gunicorn[359712]: 2025-08-12 15:45:42,682 django.request ERROR    Internal Server Error: /api/eamena/submit
 gunicorn[359712]: Traceback (most recent call last):
 gunicorn[359712]:   File "/opt/arches/HeritageBridge/ENV/lib/python3.9/site-packages/django/core/handlers/exception.py", line 35, in inner
 gunicorn[359712]:     response = get_response(request)
 gunicorn[359712]:   File "/opt/arches/HeritageBridge/ENV/lib/python3.9/site-packages/django/core/handlers/base.py", line 128, in _get_response
 gunicorn[359712]:     response = self.process_exception_by_middleware(e, request)
 gunicorn[359712]:   File "/opt/arches/HeritageBridge/ENV/lib/python3.9/site-packages/django/core/handlers/base.py", line 126, in _get_response
 gunicorn[359712]:     response = wrapped_callback(request, *callback_args, **callback_kwargs)
 gunicorn[359712]:   File "/opt/arches/HeritageBridge/ENV/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
 gunicorn[359712]:     return view_func(*args, **kwargs)
 gunicorn[359712]:   File "/opt/arches/HeritageBridge/herbridge/main/views.py", line 144, in submit_image_for_resource
 gunicorn[359712]:     response = arches_api.submit_image_report(json.loads(request.body))
 gunicorn[359712]:   File "/opt/arches/HeritageBridge/herbridge/main/api.py", line 560, in submit_image_report
 gunicorn[359712]:     if response.status_code in [500]:
 gunicorn[359712]: AttributeError: 'int' object has no attribute 'status_code'

The corresponding Arches error was:

Details
 gunicorn[1562]: 2025-08-12 10:45:42,455 arches.app.views.tile ERROR    Unable to save. [Tile id: ]                      [Exception message: Multiple Tiles for Cardinality-1 Nodegroup | nodegroupid: b528b064-5189-11ea-a3f7-02e7594ce0a0, resourceinstanceid: 44781aee-6c97-465b-ae1e-98233dade83d, parenttileid: root
 gunicorn[1562]: CONTEXT:  PL/pgSQL function __arches_check_excess_tiles_trigger_function() line 9 at RAISE
 gunicorn[1562]: ]                      [Exception trace: Traceback (most recent call last):
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
 gunicorn[1562]:     return self.cursor.execute(sql, params)
 gunicorn[1562]: psycopg2.errors.CardinalityViolation: Multiple Tiles for Cardinality-1 Nodegroup | nodegroupid: b528b064-5189-11ea-a3f7-02e7594ce0a0, resourceinstanceid: 44781aee-6c97-465b-ae1e-98233dade83d, parenttileid: root
 gunicorn[1562]: CONTEXT:  PL/pgSQL function __arches_check_excess_tiles_trigger_function() line 9 at RAISE
 gunicorn[1562]: The above exception was the direct cause of the following exception:
 gunicorn[1562]: Traceback (most recent call last):
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/arches/app/views/tile.py", line 143, in post
 gunicorn[1562]:     tile.save(request=request, transaction_id=transaction_id)
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/arches/app/models/tile.py", line 428, in save
 gunicorn[1562]:     super(Tile, self).save(*args, **kwargs)
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/arches/app/models/models.py", line 1084, in save
 gunicorn[1562]:     super(TileModel, self).save(*args, **kwargs)  # Call the "real" save() method.
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/models/base.py", line 739, in save
 gunicorn[1562]:     self.save_base(using=using, force_insert=force_insert,
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/models/base.py", line 776, in save_base
 gunicorn[1562]:     updated = self._save_table(
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/models/base.py", line 881, in _save_table
 gunicorn[1562]:     results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/models/base.py", line 919, in _do_insert
 gunicorn[1562]:     return manager._insert(
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
 gunicorn[1562]:     return getattr(self.get_queryset(), name)(*args, **kwargs)
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/models/query.py", line 1270, in _insert
 gunicorn[1562]:     return query.get_compiler(using=using).execute_sql(returning_fields)
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1416, in execute_sql
 gunicorn[1562]:     cursor.execute(sql, params)
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
 gunicorn[1562]:     return super().execute(sql, params)
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
 gunicorn[1562]:     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
 gunicorn[1562]:     return executor(sql, params, many, context)
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
 gunicorn[1562]:     return self.cursor.execute(sql, params)
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
 gunicorn[1562]:     raise dj_exc_value.with_traceback(traceback) from exc_value
 gunicorn[1562]:   File "/opt/arches/ENV/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
 gunicorn[1562]:     return self.cursor.execute(sql, params)
 gunicorn[1562]: django.db.utils.ProgrammingError: Multiple Tiles for Cardinality-1 Nodegroup | nodegroupid: b528b064-5189-11ea-a3f7-02e7594ce0a0, resourceinstanceid: 44781aee-6c97-465b-ae1e-98233dade83d, parenttileid: root
 gunicorn[1562]: CONTEXT:  PL/pgSQL function __arches_check_excess_tiles_trigger_function() line 9 at RAISE
 gunicorn[1562]: ]
 gunicorn[1562]: Internal Server Error: /tile

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions