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

TypeError at /en/exercise/add/ #636

Closed
Wartz opened this issue Mar 19, 2021 · 6 comments
Closed

TypeError at /en/exercise/add/ #636

Wartz opened this issue Mar 19, 2021 · 6 comments
Milestone

Comments

@Wartz
Copy link

Wartz commented Mar 19, 2021

Steps to Reproduce

Latest docker build (with debug on) pulled from github.

I am not sure how to consistently reproduce it, but on the regular when adding a new exercise, django produces a type error that seems to be related to selection of a license.

I have not seen the error if I make sure to actively select a license from the dropdown menu.

Doing things like reloading the site in an incognito window seems to work the best to get around it.

Expected results:
Add exercise -> click checkboxes and type words -> hit submit -> done.

Actual results:
Django Fails to POST the new workout with an error saying an 'id' expected a number but got <License: Creative Commons Attribution Share Alike 3 (CC-BY-SA 3)>

Logs
Request Method: | POST
-- | --
http://localhost/en/exercise/add/
3.1.7
TypeError
Field 'id' expected a number but got <License:  Creative Commons Attribution Share Alike 3 (CC-BY-SA 3)>.
/usr/local/lib/python3.8/dist-packages/django/db/models/fields/__init__.py, line 1776, in get_prep_value
/usr/bin/python3
3.8.5
['/usr/local/bin',  '/usr/lib/python38.zip',  '/usr/lib/python3.8',  '/usr/lib/python3.8/lib-dynload',  '/usr/local/lib/python3.8/dist-packages',  '/home/wger/src',  '/usr/lib/python3/dist-packages']

Environment:


Request Method: POST
Request URL: http://localhost/en/exercise/add/

Django Version: 3.1.7
Python Version: 3.8.5
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.messages',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.staticfiles',
 'django_extensions',
 'storages',
 'wger.config',
 'wger.core',
 'wger.mailer',
 'wger.exercises',
 'wger.gym',
 'wger.manager',
 'wger.nutrition',
 'wger.software',
 'wger.utils',
 'wger.weight',
 'captcha',
 'django.contrib.sitemaps',
 'easy_thumbnails',
 'compressor',
 'crispy_forms',
 'rest_framework',
 'rest_framework.authtoken',
 'django_filters',
 'django_bootstrap_breadcrumbs',
 'corsheaders')
Installed Middleware:
('corsheaders.middleware.CorsMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'wger.utils.middleware.JavascriptAJAXRedirectionMiddleware',
 'wger.utils.middleware.WgerAuthenticationMiddleware',
 'wger.utils.middleware.RobotsExclusionMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.locale.LocaleMiddleware')



Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/__init__.py", line 1774, in get_prep_value
    return int(value)

The above exception (int() argument must be a string, a bytes-like object or a number, not 'License') was the direct cause of the following exception:
  File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/wger/src/wger/exercises/views/exercises.py", line 339, in dispatch
    return super(ExerciseAddView, self).dispatch(request, *args, **kwargs)
  File "/home/wger/src/wger/utils/generic_views.py", line 199, in dispatch
    return super(WgerFormMixin, self).dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/mixins.py", line 52, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/django/views/generic/edit.py", line 172, in post
    return super().post(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/django/views/generic/edit.py", line 142, in post
    return self.form_valid(form)
  File "/home/wger/src/wger/exercises/views/exercises.py", line 317, in form_valid
    license=License.objects.get(id=form.cleaned_data['license']),
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 418, in get
    clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 942, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 962, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 969, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/sql/query.py", line 1358, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/sql/query.py", line 1377, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/sql/query.py", line 1319, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/sql/query.py", line 1165, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/lookups.py", line 24, in __init__
    self.rhs = self.get_prep_lookup()
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/lookups.py", line 76, in get_prep_lookup
    return self.lhs.output_field.get_prep_value(self.rhs)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/__init__.py", line 1776, in get_prep_value
    raise e.__class__(

Exception Type: TypeError at /en/exercise/add/
Exception Value: Field 'id' expected a number but got <License:  Creative Commons Attribution Share Alike 3 (CC-BY-SA 3)>.
@rolandgeider
Copy link
Member

Thanks, will try to reproduce

@Wartz
Copy link
Author

Wartz commented Mar 19, 2021

I think I narrowed it down some more.

I can consistently get the error by selecting a custom item from the Category menu when adding an exercise.

If I hit backspace, change the category to one of the default ones (Except for "Calves", oddly enough) and resubmit, the new exercise is successfully submitted.

I can go to the exercise afterwards and edit the category to a custom one just fine.

@rolandgeider
Copy link
Member

After selecting a category the license breaks? Interesting 😅

@Wartz
Copy link
Author

Wartz commented Mar 19, 2021

Specifically a custom category or the default Calves, weirdly. The rest of the default categories do not seem to trigger the error.

Let me know if there is something I can do to help trace this down further.

Thanks for looking into it!

@rolandgeider
Copy link
Member

I have commited a fix, if you wait till the docker images are rebuilt and pull, it should be fixed

@rolandgeider rolandgeider added this to the 2.0 milestone Mar 19, 2021
@Wartz
Copy link
Author

Wartz commented Mar 19, 2021

Hot dang that was quick!

Thanks a bunch.

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

No branches or pull requests

2 participants