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 when using hstore.DictionaryField in a unique_together clause #44

Closed
etianen opened this issue May 13, 2014 · 8 comments
Closed
Assignees
Labels

Comments

@etianen
Copy link

etianen commented May 13, 2014

I'm using Django 1.7 (latest pull from stable/1.7 branch), but can recreate the issue with Django 1.6.

Full traceback below:

Traceback:
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/core/handlers/base.py" in get_response
  113.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/lib/python2.7/site-packages/newrelic-2.18.1.15/newrelic/hooks/framework_django.py" in wrapper
  492.                 return wrapped(*args, **kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/contrib/admin/options.py" in wrapper
  550.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/utils/decorators.py" in _wrapped_view
  105.                     response = view_func(request, *args, **kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/contrib/admin/sites.py" in inner
  204.             return view(request, *args, **kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/contrib/admin/options.py" in add_view
  1417.         return self.changeform_view(request, None, form_url, extra_context)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/utils/decorators.py" in _wrapper
  29.             return bound_func(*args, **kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/utils/decorators.py" in _wrapped_view
  105.                     response = view_func(request, *args, **kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/utils/decorators.py" in bound_func
  25.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/transaction.py" in inner
  394.                 return func(*args, **kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/contrib/admin/options.py" in changeform_view
  1359.             if form.is_valid():
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/forms/forms.py" in is_valid
  162.         return self.is_bound and not bool(self.errors)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/forms/forms.py" in errors
  154.             self.full_clean()
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/forms/forms.py" in full_clean
  355.         self._post_clean()
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/forms/models.py" in _post_clean
  430.             self.validate_unique()
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/forms/models.py" in validate_unique
  439.             self.instance.validate_unique(exclude=exclude)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/base.py" in validate_unique
  802.         errors = self._perform_unique_checks(unique_checks)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/base.py" in _perform_unique_checks
  886.             qs = model_class._default_manager.filter(**lookup_kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/manager.py" in manager_method
  92.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/query.py" in filter
  689.         return self._filter_or_exclude(False, *args, **kwargs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/query.py" in _filter_or_exclude
  707.             clone.query.add_q(Q(*args, **kwargs))
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/sql/query.py" in add_q
  1287.         clause, require_inner = self._add_q(where_part, self.used_aliases)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/sql/query.py" in _add_q
  1314.                     current_negated=current_negated, connector=connector)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/sql/query.py" in build_filter
  1186.             condition = self.build_lookup(lookups, col, value)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/sql/query.py" in build_lookup
  1094.                     return final_lookup(lhs, rhs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/lookups.py" in __init__
  80.         self.rhs = self.get_prep_lookup()
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/lookups.py" in get_prep_lookup
  83.         return self.lhs.output_type.get_prep_lookup(self.lookup_name, self.rhs)
File "/Users/dave/Workspace/willhill_bingo/venv/src/django/django/db/models/fields/__init__.py" in get_prep_lookup
  632.             return value.prepare()
@etianen
Copy link
Author

etianen commented May 13, 2014

Ooops, missed a bit:

Exception Type: TypeError at /admin/events/action/add/
Exception Value: prepare() takes exactly 2 arguments (1 given)

@nemesifier
Copy link
Member

could you show the code that causes the exception?

@etianen
Copy link
Author

etianen commented May 13, 2014

In my case, it's a model like this:

class Action(models.Model):

    description = models.CharField(
        max_length = 255,
    )

    type = models.PositiveSmallIntegerField(
        choices = TYPE_CHOICES,
    )

    qualifiers = hstore.DictionaryField(
        blank = True,
    )

    def __unicode__(self):
        return self.description

    class Meta:
        ordering = ("type", "description",)
        unique_together = (
            # Cannot use this yet, due to https://github.com/djangonauts/django-hstore/issues/44 
            # ("type", "qualifiers",), 
        )

The issue appears to occur during model validation in the admin add_view.

@nemesifier
Copy link
Member

thanks, will look into it asap

@niwinz niwinz self-assigned this Jun 18, 2014
@niwinz niwinz added the bug label Jun 18, 2014
@niwinz
Copy link
Member

niwinz commented Jun 21, 2014

Hi! I have tested in in an isolated environment with same model configuration and with both django versions (1.6 and 1.7) with python3 and python2 and I can not reproduce the error.

This happens when you run syncdb, I'm right?

@etianen
Copy link
Author

etianen commented Jun 21, 2014

Nope. It happens when the app serves it's first request, and only occurs intermittently.

If the problem occurs, then the app remains broken with this error until manually restarted. A restart usually fixes it, as the problem only occurs rarely.

On 21 Jun 2014, at 09:50, Andrey Antukh notifications@github.com wrote:

Hi! I have tested in in an isolated environment with same model configuration and with both django versions (1.6 and 1.7) with python3 and python2 and I can not reproduce the error.

This happens when you run syncdb, I'm right?


Reply to this email directly or view it on GitHub.

@niwinz
Copy link
Member

niwinz commented Jun 21, 2014

Ok, I just opened a pull request with possible fix for this issue.

nemesifier added a commit that referenced this issue Jun 23, 2014
Possible fix for #44: wrong prepare method
@nemesifier
Copy link
Member

fixed by #49

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

No branches or pull requests

3 participants