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

Intermittent TypeError related to lru_cache? #258

Closed
triopter opened this issue Aug 18, 2021 · 3 comments
Closed

Intermittent TypeError related to lru_cache? #258

triopter opened this issue Aug 18, 2021 · 3 comments

Comments

@triopter
Copy link

Hello! I'm intermittently getting a 500 from the backend when calling a component method. Here's an example payload:

{"id":"Ck9kDpm5:table-row:159","data":{"row":{"table":37,"title":"Memory financial give.","order":720,"pk":159}},"checksum":"5YxwpjTk","actionQueue":[{"type":"callMethod","payload":{"name":"print_saving(122)"},"partials":[]}],"epoch":1629327423683,"hash":"3ffoSeN3"}

And a sample traceback:

Field 'id' expected a number but got <TableCell: Certain usually speak pressure gun image manager. Whose prevent state indicate society beautiful decide. Clearly financial shake seem director.>.

Request Method: POST
Request URL: http://localhost:8000/unicorn/message/table-row
Django Version: 3.2.6
Python Version: 3.8.2
Server time: Wed, 18 Aug 2021 22:57:04 +0000
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'tables',
 'django_unicorn',
 'django_seed']
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 "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 1823, in get_prep_value
    return int(value)

The above exception (int() argument must be a string, a bytes-like object or a number, not 'TableCell') was the direct cause of the following exception:
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "<decorator-gen-26>", line 2, in message
    <source code not available>
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django_unicorn/decorators.py", line 66, in timed
    result = func(*args, **kwargs)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django_unicorn/views/__init__.py", line 42, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/views/decorators/http.py", line 40, in inner
    return func(request, *args, **kwargs)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django_unicorn/views/__init__.py", line 460, in message
    json_result = _handle_component_request(request, component_request)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django_unicorn/views/__init__.py", line 310, in _handle_component_request
    return _process_component_request(request, component_request)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django_unicorn/views/__init__.py", line 118, in _process_component_request
    ) = call_method.handle(component_request, component, action.payload)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django_unicorn/views/action_parsers/call_method.py", line 86, in handle
    return_data.value = _call_method_name(component, method_name, args, kwargs)
  File "<decorator-gen-24>", line 2, in _call_method_name
    <source code not available>
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django_unicorn/decorators.py", line 66, in timed
    result = func(*args, **kwargs)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django_unicorn/views/action_parsers/call_method.py", line 132, in _call_method_name
    model = DbModel.objects.get(**{key: value})
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/query.py", line 424, in get
    clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/query.py", line 941, in filter
    return self._filter_or_exclude(False, args, kwargs)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/query.py", line 961, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, args, kwargs)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/query.py", line 968, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1393, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1412, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1347, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1193, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/lookups.py", line 25, in __init__
    self.rhs = self.get_prep_lookup()
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/lookups.py", line 77, in get_prep_lookup
    return self.lhs.output_field.get_prep_value(self.rhs)
  File "/Users/triopter/.local/share/virtualenvs/poc_uni-QNOZ3vZ_/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 1825, in get_prep_value
    raise e.__class__(

Exception Type: TypeError at /unicorn/message/table-row
Exception Value: Field 'id' expected a number but got <TableCell: Certain usually speak pressure gun image manager. Whose prevent state indicate society beautiful decide. Clearly financial shake seem director.>.```

Debugging, I determined that the only cases in which the error was occurring were the ones in which the body of `django_unicorn.call_method_parser.parse_call_method_name` was not entered.  Commenting out the `lru_cache` decorator has resolved the problem, and it now succeeds consistently.  I suspect this has something to do with hydration changing a cached value somewhere.
@adamghill
Copy link
Owner

Hmm, interesting. I don't think I've ever seen this happen while I've been testing. Any chance you could fork this repo and reproduce this in the example project? That way I could see more easily what is going on, thanks!

@adamghill
Copy link
Owner

If I specify typed=True (as referenced in https://docs.python.org/3/library/functools.html#functools.lru_cache) it would prevent the exception (although, not sure if there is a separate issue that is happening). I'm going to try that and you can let me know if it clears up.

@adamghill
Copy link
Owner

Done in 6d72278. Closing, but feel free to open this again if you see it continue to happen in 0.34.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants