#12079 closed (fixed)
queryset.exists() doesn’t work correctly
Reported by: | ramusus | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | ramusus@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I don't understand is it normal?
In [17]: User.objects.filter(pk=0) Out[17]: [] In [18]: User.objects.filter(pk=0).exists() Out[18]: True
The exists() should return False result in this case, I think. This is revision 11653 (Development version)
I have related problem with unique validating of inlineformset and I found that the reason is queryset.exists() doesn't work correctly
Attachments (1)
Change History (11)
comment:1 by , 15 years ago
Cc: | added |
---|
comment:2 by , 15 years ago
comment:3 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
It's failing on MySQL, at least. This code:
http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/query.py#L2381
simply returns result when the connection can use chunked reads. For mysql result is a callable-interator and bool(<callable-interator>) is True.
by , 15 years ago
Attachment: | 12079.diff added |
---|
comment:4 by , 15 years ago
I've attached a possible patch but I don't have much of a clue when it comes to the ORM so someone with more of one in that area should see if there's a better way, etc.
comment:5 by , 15 years ago
(No tests needed for this fix...a lookup test added in r11647 is currently failing on backends where this problem occurs.)
comment:6 by , 15 years ago
Can you provide some more information about your setup, such as db backend?
DATABASE_ENGINE = 'postgresql_psycopg2'
comment:7 by , 15 years ago
Karen, that patch looks correct. I didn't notice this as Jacob committed a different version than my patch (which included a call to list()).
comment:8 by , 15 years ago
Has patch: | set |
---|---|
milestone: | → 1.2 |
Triage Stage: | Accepted → Ready for checkin |
Version: | 1.1 → SVN |
comment:9 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This works correctly for me.
Can you provide some more information about your setup, such as db backend?