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

Bug in exclude() using contains #126

Open
jmbowman opened this issue Jul 14, 2015 · 2 comments
Open

Bug in exclude() using contains #126

jmbowman opened this issue Jul 14, 2015 · 2 comments

Comments

@jmbowman
Copy link

I have a query that includes a condition like the following:

.exclude(hstore_field__contains={'key_name': 'value'})

In django-hstore 1.3.4 and earlier, this translated to the following SQL:

WHERE NOT ("app_model"."hstore_field" @> hstore(ARRAY['key_name'], ARRAY['value']) AND "app_model"."hstore_field" IS NOT NULL)

But starting in 1.3.5, it changed to the following:

WHERE NOT (("app_model"."hstore_field"->'key_name') = 'value' AND "app_model"."hstore_field" IS NOT NULL)

The latter breaks down when the hstore field is not null but doesn't contain the key. It simplifies as follows:

WHERE NOT (NULL = 'value' AND TRUE)
WHERE NOT (NULL AND TRUE)
WHERE NOT NULL
WHERE NULL

Hence the condition ultimately evaluates as false and the record is excluded, even though we were trying to get records like this one that don't contain the specified key/value combination. The SQL from earlier versions works correctly, because it doesn't throw a NULL into the boolean operations.

@dannosaur
Copy link

Yea, I'm seeing this as well. Trying to exclude records that have a specific key in the dictionary isn't yielding any rows at all. I'm using django_hstore 1.4.2.

@andrewhayes1979
Copy link
Contributor

+1

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

3 participants