Opened 14 years ago
Last modified 11 years ago
#14786 closed Bug
get_db_prep_lookup call get_prep_value twice for each value if prepared == False — at Version 4
Reported by: | homm | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | sprintdec2010 fields lookup |
Cc: | Jonas H. | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
In db.models.fields.Field get_db_prep_lookup()
check if value is prepared and prepare it:
def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False): "Returns field's value prepared for database lookup." if not prepared: value = self.get_prep_lookup(lookup_type, value)
get_prep_lookup()
call get_prep_value()
for every value.
But look next:
elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte'): return [self.get_db_prep_value(value, connection=connection, prepared=prepared)] elif lookup_type in ('range', 'in'): return [self.get_db_prep_value(v, connection=connection, prepared=prepared) for v in value]
Prepared flag not changed and get_db_prep_value()
call get_prep_value()
through get_db_prep_value()
again!
I think get_db_prep_lookup()
should call get_db_prep_value()
always with prepared == True
.
elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte'): return [self.get_db_prep_value(value, connection=connection, prepared=True)] elif lookup_type in ('range', 'in'): return [self.get_db_prep_value(v, connection=connection, prepared=True) for v in value]
This bug is still unnoticed because in standard ORM get_db_prep_lookup()
always calls with prepared == True
.
Change History (6)
comment:1 by , 14 years ago
Cc: | added |
---|
by , 14 years ago
Attachment: | 14786_fix_with_tests.diff added |
---|
comment:2 by , 14 years ago
Has patch: | set |
---|---|
Keywords: | sprintdec2010 fields lookup added |
Triage Stage: | Unreviewed → Accepted |
Version: | 1.2 → SVN |
comment:3 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:4 by , 13 years ago
Description: | modified (diff) |
---|---|
Easy pickings: | unset |
Patch needs improvement: | set |
UI/UX: | unset |
Patch doesn't apply cleanly, will try to rebase.
by , 13 years ago
Attachment: | ticket14786.diff added |
---|
Fix with a regression test.