Skip to content

AssertionError on identical chained queries #85

@emperorcezar

Description

@emperorcezar

The complier throws an error when there are two chained identical filters. The case that brought me to find this was when I creating a form for the admin.

I have the following line of code:

self.fields['faculty'].queryset = User.objects.filter(pk__in = [faculty.user.pk for faculty in faculty_list])

In the case where there is only one faculty user, and I create the object (in the admin form) selecting that one user, I will get an error triggered by the following line of django_mongodb_engine/compiler.py on line 245:

assert all(key not in existing for key in lookup.keys()), [lookup, existing]

What is causing this case to occur is the following code in the clean() method of Django's ModelChoiceField

qs = self.queryset.filter(**{'%s__in' % key: value})

where the value is the choice I selected.

Puting both of these together you get the query

User.objects.filter(pk__in = [u'4eaef5d7bb6933592e000010']).filter(pk__in = [u'4eaef5d7bb6933592e000010'])

and then the AssertionError triggers.

I'm trying to work on a patch right now, but I'm not real familiar with the complier. Any advice appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions