#14786: get_db_prep_lookup call get_prep_value twice for each value if prepared 
==
False
-------------------------------------+-------------------------------------
     Reporter:  homm                 |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  SVN
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:  sprintdec2010        |      Needs documentation:  0
  fields lookup                      |  Patch needs improvement:  1
    Has patch:  1                    |                    UI/UX:  0
  Needs tests:  0                    |
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by lrekucki):

 * needs_better_patch:  0 => 1
 * ui_ux:   => 0
 * easy:   => 0


Old description:

> 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.

New description:

 In db.models.fields.Field {{{get_db_prep_lookup()}}} check if value is
 prepared and prepare it:

 {{{#!python
 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:
 {{{#!python
 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}}}.
 {{{#!python
 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}}}.

--

Comment:

 Patch doesn't apply cleanly, will try to rebase.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/14786#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to