Django-jet: Error when trying to add item with pk not of Integer type

Created on 30 Jan 2017  路  5Comments  路  Source: geex-arts/django-jet

I have a table that has pk of string and when I try to add an item to this table django-jet crashes with the error:

ValueError: invalid literal for int() with base 10: ''

All the other tables with numeric PKs work fine. django-jet version 1.0.4

HEre is the complete stack trace

Internal Server Error: /admin/inventory/item/add/
Traceback (most recent call last):
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/core/handlers/exception.py", line 39, in inner
    response = get_response(request)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py", line 30, in inner
    return func(*args, **kwds)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/contrib/admin/options.py", line 544, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/contrib/admin/sites.py", line 211, in inner
    return view(request, *args, **kwargs)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/contrib/admin/options.py", line 1509, in add_view
    return self.changeform_view(request, None, form_url, extra_context)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/utils/decorators.py", line 67, in _wrapper
    return bound_func(*args, **kwargs)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/utils/decorators.py", line 63, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py", line 30, in inner
    return func(*args, **kwds)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/contrib/admin/options.py", line 1464, in changeform_view
    formsets, inline_instances = self._create_formsets(request, form.instance, change=False)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/contrib/admin/options.py", line 1815, in _create_formsets
    formsets.append(FormSet(**formset_params))
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/contrib/contenttypes/forms.py", line 30, in __init__
    self.ct_fk_field.name: self.instance.pk,
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/db/models/query.py", line 796, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/db/models/query.py", line 814, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/db/models/sql/query.py", line 1227, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/db/models/sql/query.py", line 1253, in _add_q
    allow_joins=allow_joins, split_subq=split_subq,
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/db/models/sql/query.py", line 1187, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/db/models/sql/query.py", line 1083, in build_lookup
    return final_lookup(lhs, rhs)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/db/models/lookups.py", line 19, in __init__
    self.rhs = self.get_prep_lookup()
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/db/models/lookups.py", line 59, in get_prep_lookup
    return self.lhs.output_field.get_prep_value(self.rhs)
  File "/Users/delio/.virtualenvs/inventory/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1832, in get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: ''
[30/Jan/2017 14:02:20] "GET /admin/inventory/item/add/ HTTP/1.1" 500 186330

Most helpful comment

How did you solve it ? Because the users I have use a 'username' as a primary key and not an integer.
This makes django-jet completely fail

All 5 comments

The problem was related to another app.

@jangeador I have the exact same issue, do you remember which was causing the issue ?

@DEKHTIARJonathan Yes, it was related with an app I created which used a CharField as its primary key.

How did you solve it ? Because the users I have use a 'username' as a primary key and not an integer.
This makes django-jet completely fail

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pwndr00t picture pwndr00t  路  4Comments

Zundrium picture Zundrium  路  9Comments

RamizSami picture RamizSami  路  4Comments

socrec picture socrec  路  8Comments

andreamanni picture andreamanni  路  4Comments