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

Internal server error after column type is converted from text to boolean with display options #1228

Closed
pavish opened this issue Mar 25, 2022 · 4 comments · Fixed by #1251
Closed
Assignees
Labels
type: bug Something isn't working work: backend Related to Python, Django, and simple SQL
Milestone

Comments

@pavish
Copy link
Member

pavish commented Mar 25, 2022

To Reproduce

  • Create a new text column
  • Patch the column from text to boolean with display options.
    {
      type: 'boolean',
      type_options: {},
      display_options: {
        input: 'dropdown',
        custom_labels: {
          TRUE: 'TRUE'
          FALSE: 'FALSE'
        }
      }
    }
  • Notice that the request succeeds.
  • Send a subsequent request to get all columns of the table. Notice the 500 error.
  • Try loading the frontend, a debug page with the error message appears.
  • This does not happen always, happens intermittently and I end up having to drop the table directly in the db inorder to get things working again.

Error message:

[{"code":4999,"message":"\"Got KeyError when attempting to get a value for field `input` on serializer `BooleanDisplayOptionSerializer`.\\nThe serializer field might be named incorrectly and not match any attribute or key on the `dict` instance.\\nOriginal exception text was: 'input'.\"","field":null,"detail":null}]

Error log:

Environment:


Request Method: GET
Request URL: http://localhost:8000/mathesar_tables/1/?t=W1tdLG51bGxd

Django Version: 3.1.14
Python Version: 3.9.8
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 "/usr/local/lib/python3.9/site-packages/rest_framework/fields.py", line 457, in get_attribute
    return get_attribute(instance, self.source_attrs)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/fields.py", line 95, in get_attribute
    instance = instance[attr]

During handling of the above exception ('input'), 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 "/code/mathesar/views.py", line 109, in schema_home
    'common_data': get_common_data(request, database, schema)
  File "/code/mathesar/views.py", line 55, in get_common_data
    'tables': get_table_list(request, schema),
  File "/code/mathesar/views.py", line 35, in get_table_list
    return table_serializer.data
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 745, in data
    ret = super().data
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 246, in data
    self._data = self.to_representation(self.instance)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 663, in to_representation
    return [
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 664, in <listcomp>
    self.child.to_representation(item) for item in iterable
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 515, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 663, in to_representation
    return [
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 664, in <listcomp>
    self.child.to_representation(item) for item in iterable
  File "/code/mathesar/api/serializers/columns.py", line 67, in to_representation
    return super().to_representation(instance)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 515, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 502, in to_representation
    attribute = field.get_attribute(instance)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/fields.py", line 490, in get_attribute
    raise type(exc)(msg)

Exception Type: KeyError at /mathesar_tables/1/
Exception Value: "Got KeyError when attempting to get a value for field `input` on serializer `BooleanDisplayOptionSerializer`.\nThe serializer field might be named incorrectly and not match any attribute or key on the `dict` instance.\nOriginal exception text was: 'input'."
@pavish pavish added type: bug Something isn't working work: backend Related to Python, Django, and simple SQL ready Ready for implementation labels Mar 25, 2022
@pavish pavish added this to the [07] Initial Data Types milestone Mar 25, 2022
@silentninja silentninja self-assigned this Mar 25, 2022
@silentninja silentninja added status: started and removed ready Ready for implementation labels Mar 25, 2022
@silentninja silentninja changed the title Internal server error after column type is convered from text to boolean with display options Internal server error after column type is converted from text to boolean with display options Mar 28, 2022
Repository owner moved this from Started to Done in [NO LONGER USED] Mathesar work tracker Apr 11, 2022
@pavish
Copy link
Member Author

pavish commented Apr 18, 2022

@silentninja @kgodey

I'm still the same error quite frequently for boolean type. But it's intermittent and I can't seem to reproduce it.

"Got KeyError when attempting to get a value for field 'input' on serializer 'BooleanDisplayOptionSerializer'.\nThe serializer field might be named incorrectly and not match any attribute or key on the 'dict' instance.\nOriginal exception text was: 'input'."

Adding a default to input in BooleanDisplayOptionSerializer seems to fix the issue for me.

This commit seems to remove the default. Perhaps we expect the value to always be present but it is missing due to some race condition.

I'm re-opening this issue since it's essentially the same issue and the PRs are related.

Environment:


Request Method: GET
Request URL: http://localhost:8000/mathesar_tables/1/?t=W1tbMSwxMSxbWzEsNTAwXSxbXSxbXSxbImFuZCIsW11dXV1dLFsxLDExXV0

Django Version: 3.1.14
Python Version: 3.9.8
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 "/usr/local/lib/python3.9/site-packages/rest_framework/fields.py", line 457, in get_attribute
    return get_attribute(instance, self.source_attrs)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/fields.py", line 95, in get_attribute
    instance = instance[attr]

During handling of the above exception ('input'), 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 "/code/mathesar/views.py", line 109, in schema_home
    'common_data': get_common_data(request, database, schema)
  File "/code/mathesar/views.py", line 55, in get_common_data
    'tables': get_table_list(request, schema),
  File "/code/mathesar/views.py", line 35, in get_table_list
    return table_serializer.data
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 745, in data
    ret = super().data
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 246, in data
    self._data = self.to_representation(self.instance)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 663, in to_representation
    return [
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 664, in <listcomp>
    self.child.to_representation(item) for item in iterable
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 515, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 663, in to_representation
    return [
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 664, in <listcomp>
    self.child.to_representation(item) for item in iterable
  File "/code/mathesar/api/serializers/columns.py", line 67, in to_representation
    return super().to_representation(instance)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 515, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 502, in to_representation
    attribute = field.get_attribute(instance)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/fields.py", line 490, in get_attribute
    raise type(exc)(msg)

Exception Type: KeyError at /mathesar_tables/1/
Exception Value: "Got KeyError when attempting to get a value for field `input` on serializer `BooleanDisplayOptionSerializer`.\nThe serializer field might be named incorrectly and not match any attribute or key on the `dict` instance.\nOriginal exception text was: 'input'."

@pavish pavish reopened this Apr 18, 2022
Repository owner moved this from Done to Ready in [NO LONGER USED] Mathesar work tracker Apr 18, 2022
@silentninja
Copy link
Contributor

silentninja commented Apr 19, 2022

@pavish I am able to reproduce the bug and found the cause of the problem. I am working on a fix.

@silentninja
Copy link
Contributor

silentninja commented May 6, 2022

@pavish We had a few Display option bug fixes recently, did you happen to come across this issue in the latest master branch?

@kgodey
Copy link
Contributor

kgodey commented Jul 19, 2022

I'm closing this, we can reopen if it comes up again.

@kgodey kgodey closed this as completed Jul 19, 2022
Repository owner moved this from Ready to Done in [NO LONGER USED] Mathesar work tracker Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working work: backend Related to Python, Django, and simple SQL
Projects
No open projects
3 participants