Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mathesar Unable to Retrieve Records from Database #3375

Closed
MrChadMWood opened this issue Dec 22, 2023 · 7 comments
Closed

Mathesar Unable to Retrieve Records from Database #3375

MrChadMWood opened this issue Dec 22, 2023 · 7 comments
Assignees
Labels
needs: user feedback We are waiting for a user to answer questions or provide feedback on our fix type: bug Something isn't working user reported Reported by a Mathesar user work: backend Related to Python, Django, and simple SQL
Milestone

Comments

@MrChadMWood
Copy link

MrChadMWood commented Dec 22, 2023

Description

Mathesar is unable to retrieve records, winds up saying no records found.

Expected behavior

Records should be retrieved without error and displayed. If an error does occur, maybe it is better to indicate this from the frontend instead of just showing "No Records Found".

To Reproduce

I am unsure what caused the issue. Please see the additional context.

Environment

  • OS: Linux
  • Browser: Firefox
  • Other info: This appears to be a serverside error.

Additional context

Log statement of the error:

ERROR:django.request:Internal Server Error: /api/db/v0/tables/393/records/
Traceback (most recent call last):
  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/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 466, in handle_exception
    response = exception_handler(exc, context)
  File "/code/mathesar/exception_handlers.py", line 59, in mathesar_exception_handler
    raise exc
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/code/mathesar/api/db/viewsets/records.py", line 73, in list
    records = paginator.paginate_queryset(
  File "/code/mathesar/api/pagination.py", line 88, in paginate_queryset
    preview_metadata, preview_columns = get_preview_info(table.id)
  File "/code/mathesar/utils/preview.py", line 93, in get_preview_info
    preview_info, columns = _preview_info_by_column_id(
  File "/code/mathesar/utils/preview.py", line 14, in _preview_info_by_column_id
    for fk_constraint in fk_constraints:
  File "/code/mathesar/utils/preview.py", line 113, in _filter_out_circular_dependency_columns
    referent_column = fk_constraint.referent_columns[0]
  File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 325, in __getitem__
    return qs._result_cache[0]
IndexError: list index out of range

Without better knowledge of Mathesar's internal operations, it looks to me like qs._result_cache is an empty list- causing this error to be thrown. I'm not sure how or why the list would be empty.

Image of error from frontend:
image

@MrChadMWood MrChadMWood added needs: triage This issue has not yet been reviewed by a maintainer type: bug Something isn't working labels Dec 22, 2023
@MrChadMWood
Copy link
Author

Not sure if it matters, but those blocked requests appear to be blocked due to lack of encryption.

image

@seancolsen
Copy link
Contributor

Thanks for reporting this, @MrChadMWood. Just a brief heads up that all maintainers will be on holiday break until January 2nd. We'll help troubleshoot this with you when we return!

@kgodey kgodey added the user reported Reported by a Mathesar user label Dec 24, 2023
@kgodey kgodey added this to the v0.1.4 milestone Dec 24, 2023
@seancolsen seancolsen added work: backend Related to Python, Django, and simple SQL needs: troubleshooting Issues that we can't reproduce or need to investigate further before picking a course of action and removed needs: triage This issue has not yet been reviewed by a maintainer labels Jan 2, 2024
@seancolsen
Copy link
Contributor

@Anish9901 I've assigned this to you because I think we need a maintainer to look into this and try to reproduce it or better understand it. Can you spend some time with it and report back with your findings and recommendations for next steps?

@Anish9901
Copy link
Member

Anish9901 commented Jan 2, 2024

@MrChadMWood Does the issue persist after clicking 'Sync External Changes' button on the database page?

Regardless of whether this fixes the issue, it would be great if you could provide a mock data model of the schema within which the error occurs, as it is difficult to pinpoint the cause of the error by looking at the error logs.

@mathemancer
Copy link
Contributor

It looks like a Constraint model instance representing a foreign key has ended up in an inconsistent state w.r.t. its linked (referent) Column model instances.

@seancolsen seancolsen added needs: user feedback We are waiting for a user to answer questions or provide feedback on our fix and removed needs: troubleshooting Issues that we can't reproduce or need to investigate further before picking a course of action labels Jan 3, 2024
@seancolsen seancolsen modified the milestones: v0.1.4, Backlog Jan 3, 2024
@seancolsen
Copy link
Contributor

@MrChadMWood are you still encountering this?

I'm trying to move this issue along. We're not able to reproduce this, and it looks like we need some more info from you before we're able to help.

Was this bug just a fluke that you never saw again?

  • I so, how would you feel about closing this issue? It's worth noting that we are currently overhauling our backend architecture and moving towards a system that should make bugs like this far less likely.

  • If you are still able to reproduce it, then:

    • We'd like to know if "Sync External Changes" has any effect.
    • We'd like to know more about your schema. It would be helpful if you could give us a pg_dump --schema-only SQL file so we can see the entire structure.

@seancolsen
Copy link
Contributor

@MrChadMWood since we haven't heard from you in a while about this, I'm going to close it. We'll be happy to re-open it if we can get some more info to help our troubleshooting efforts. It's also worth mentioning that we're in the process of a substantial backend overhaul that will bring many stability improvements for Mathesar's beta release later this year. Hopefully bugs like this will go away on their own!

@seancolsen seancolsen closed this as not planned Won't fix, can't repro, duplicate, stale Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: user feedback We are waiting for a user to answer questions or provide feedback on our fix type: bug Something isn't working user reported Reported by a Mathesar user work: backend Related to Python, Django, and simple SQL
Projects
None yet
Development

No branches or pull requests

5 participants