#10432 closed (fixed)
Empty generator in "in" lookup gives incorrect SQL
Reported by: | Pavel Anossov | Owned by: | Malcolm Tredinnick |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | sql where | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Simple story, here's what happens:
> User.objects.filter(pk__in=[]) # ok [] > User.objects.filter(pk__in=(x for x in [])).query.as_sql() # ProgrammingError (...) ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 21' at line 1") > User.objects.filter(pk__in=(x for x in [])).query.as_sql() (u'SELECT (...) FROM `user` WHERE `user`.`id` IN ()', ())
A patch is included.
Attachments (1)
Change History (5)
by , 16 years ago
Attachment: | patch-10432-1.diff added |
---|
follow-up: 4 comment:1 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
That patch doesn't look like it's patching the right thing: it looks too deep in the code. I notice that this bug is somehow specific to a generator being used in the example, since using a list comprehension (or any other sequence) does't demonstrate the problem.
For next time, too, a test case is definitely required in a patch for anything like this. After all, we need to make sure it doesn't reoccur for any reason.
comment:3 by , 16 years ago
comment:4 by , 16 years ago
Replying to mtredinnick:
I notice that this bug is somehow specific to a generator being used in the example, since using a list comprehension (or any other sequence) does't demonstrate the problem.
That's why it says "generator", not "sequence" in the title ;) bool(<any generator object> is True, bool([sequence with len=0]) is False
a simple patch