mathesar-foundation / mathesar

Web application providing an intuitive user experience to databases.
https://mathesar.org/
GNU General Public License v3.0
2.41k stars 332 forks source link

AssertionError when attempting to reflect our transformed library data #1792

Open seancolsen opened 2 years ago

seancolsen commented 2 years ago

Reproduce

  1. Use our old Library data from cycle 2, supplied in schema.zip.

  2. Load books_sim.tsv and patrons_sim.tsv through the UI.

  3. Execute transform.sql via psql.

  4. Manually initiate a reflection via

    docker exec -it mathesar_service ./manage.py shell

    from mathesar.state import reset_reflection
    reset_reflection()
  5. Observe an error 'Column' object has no attribute 'primary_key'

  6. Attempt to load the web interface and observe the following error:

    Traceback ``` Environment: Request Method: GET Request URL: http://localhost:8000/mathesar_tables/1/ Django Version: 3.1.14 Python Version: 3.9.9 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'django_filters', 'django_property_filter', 'mathesar'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware'] Traceback (most recent call last): File "/code/mathesar/models/base.py", line 675, in __getattribute__ return super().__getattribute__(name) During handling of the above exception ('Column' object has no attribute 'primary_key'), another exception occurred: File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view return view_func(request, *args, **kwargs) File "/code/mathesar/views.py", line 120, in schema_home 'common_data': get_common_data(request, database, schema) File "/code/mathesar/views.py", line 68, in get_common_data 'schemas': get_schema_list(request, database), File "/code/mathesar/views.py", line 15, in get_schema_list Schema.objects.filter(database=database), File "/usr/local/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/code/mathesar/models/base.py", line 70, in get_queryset make_sure_initial_reflection_happened() File "/code/mathesar/state/base.py", line 8, in make_sure_initial_reflection_happened reset_reflection() File "/code/mathesar/state/base.py", line 27, in reset_reflection _trigger_django_model_reflection() File "/code/mathesar/state/base.py", line 31, in _trigger_django_model_reflection reflect_db_objects(metadata=get_cached_metadata()) File "/code/mathesar/state/django.py", line 44, in reflect_db_objects reflect_columns_from_tables(tables, metadata=metadata) File "/code/mathesar/state/django.py", line 123, in reflect_columns_from_tables models._compute_preview_template(table) File "/code/mathesar/models/base.py", line 859, in _compute_preview_template if column.primary_key: File "/code/mathesar/models/base.py", line 681, in __getattribute__ return getattr(self._sa_column, name) File "/code/mathesar/models/base.py", line 675, in __getattribute__ return super().__getattribute__(name) File "/code/mathesar/models/base.py", line 696, in _sa_column return self.table.sa_columns[self.name] File "/code/mathesar/models/base.py", line 675, in __getattribute__ return super().__getattribute__(name) File "/code/mathesar/state/cached_property.py", line 62, in __get__ new_value = self.original_get_fn(instance) File "/code/mathesar/models/base.py", line 718, in name assert type(name) is str Exception Type: AssertionError at /mathesar_tables/1/ Exception Value: ```

I'm putting this in "Post-Release Improvements" because it seems unlikely that a user would hit it.

silentninja commented 2 years ago

I was quick to assume that, it was a problem with the Django Column model missing the property primary_key. Instead this bugs seems to be related to metadata not being reflected correctly. I will move it back to the post release milestone.

github-actions[bot] commented 1 year ago

This issue has not been updated in 90 days and is being marked as stale.