Re: [Django] #14423: Wrong SQL on exclude with inheritance

2010-10-11 Thread Django
#14423: Wrong SQL on exclude with inheritance
---+
  Reporter:  PhiR_42   | Owner:  nobody 

Status:  new   | Milestone: 

 Component:  Database layer (models, ORM)  |   Version:  1.1

Resolution:|  Keywords:  orm 
exclude inheritance
 Stage:  Accepted  | Has_patch:  1  

Needs_docs:  0 |   Needs_tests:  0  

Needs_better_patch:  0 |  
---+
Changes (by PhiR_42):

  * needs_tests:  1 => 0

Comment:

 I did give a pretty good look at the DB tickets and couldn't find it,
 though there are some pretty similar ones (#12823 and #13937 for example).

-- 
Ticket URL: 
Django 
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 django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #14423: Wrong SQL on exclude with inheritance

2010-10-11 Thread Django
#14423: Wrong SQL on exclude with inheritance
---+
  Reporter:  PhiR_42   | Owner:  nobody 

Status:  new   | Milestone: 

 Component:  Database layer (models, ORM)  |   Version:  1.1

Resolution:|  Keywords:  orm 
exclude inheritance
 Stage:  Accepted  | Has_patch:  1  

Needs_docs:  0 |   Needs_tests:  1  

Needs_better_patch:  0 |  
---+
Changes (by Alex):

  * needs_tests:  0 => 1
  * stage:  Unreviewed => Accepted

Comment:

 FTR I'm almost positive this is a dupe.  In any event the change looks
 plausible, it needs a test though.

-- 
Ticket URL: 
Django 
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 django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #14423: Wrong SQL on exclude with inheritance

2010-10-09 Thread Django
#14423: Wrong SQL on exclude with inheritance
---+
  Reporter:  PhiR_42   | Owner:  nobody 

Status:  new   | Milestone: 

 Component:  Database layer (models, ORM)  |   Version:  1.1

Resolution:|  Keywords:  orm 
exclude inheritance
 Stage:  Unreviewed| Has_patch:  1  

Needs_docs:  0 |   Needs_tests:  0  

Needs_better_patch:  0 |  
---+
Changes (by PhiR_42):

  * has_patch:  0 => 1

-- 
Ticket URL: 
Django 
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 django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #14423: Wrong SQL on exclude with inheritance

2010-10-09 Thread Django
#14423: Wrong SQL on exclude with inheritance
---+
  Reporter:  PhiR_42   | Owner:  nobody 

Status:  new   | Milestone: 

 Component:  Database layer (models, ORM)  |   Version:  1.1

Resolution:|  Keywords:  orm 
exclude inheritance
 Stage:  Unreviewed| Has_patch:  0  

Needs_docs:  0 |   Needs_tests:  0  

Needs_better_patch:  0 |  
---+
Changes (by PhiR_42):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 I've nailed it to this particular piece of code from
 
[http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/query.py
 query.py]:
 {{{
 1073if negate:
 1074   self.promote_alias_chain(join_list)
 1075   if lookup_type != 'isnull':
 1076if len(join_list) > 1:
 1077for alias in join_list:
 1078if self.alias_map[alias][JOIN_TYPE] ==
 self.LOUTER:
 1079j_col =
 self.alias_map[alias][RHS_JOIN_COL]
 1080entry = self.where_class()
 1081entry.add((Constraint(alias, j_col,
 None), 'isnull', True), AND)
 1082entry.negate()
 1083self.where.add(entry, AND)
 1084break
 1085elif not (lookup_type == 'in'
 1086and not hasattr(value, 'as_sql')
 1087and not hasattr(value, '_as_sql')
 1088and not value) and field.null:
 1089# Leaky abstraction artifact: We have to
 specifically
 1090# exclude the "foo__in=[]" case from this
 handling, because
 1091# it's short-circuited in the Where class.
 1092# We also need to handle the case where a
 subquery is provided
 1093self.where.add((Constraint(alias, col, None),
 'isnull', False), AND)
 }}}

 Basically what happens is that when you query from a derived class you
 fall into the first if len(join_list) > 1 but since the following part is
 a elif you never get there. Hence when a nullable derived field is
 excluded (negated in the code) the null case is simply ignored. I believe
 transforming the elif into a if fixes the problem (it does for me at
 least!). This code is from trunk but this bug has been there for some time
 (I'm using 1.1.2).

-- 
Ticket URL: 
Django 
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 django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #14423: Wrong SQL on exclude with inheritance

2010-10-08 Thread Django
#14423: Wrong SQL on exclude with inheritance
--+-
 Reporter:  PhiR_42   |   Owner:  nobody
   Status:  new   |   Milestone:
Component:  Database layer (models, ORM)  | Version:  1.1   
 Keywords:  orm exclude inheritance   |   Stage:  Unreviewed
Has_patch:  0 |  
--+-
 I came across this on my inherited models. When I exclude using the base
 model qs, I get the expected results but when I do it from the derived
 model the null clause is left out. See below.

 {{{
 class TestBase(models.Model):
 test_field = models.DateField(null = True)

 class TestDerived(TestBase):
 pass
 }}}


 {{{
 >>> TestDerived.objects.create()
 
 >>> TestDerived.objects.create(test_field=datetime.date.today())
 
 >>> TestDerived.objects.exclude(test_field__lt = datetime.date.today())
 []
 >>> TestBase.objects.exclude(test_field__lt = datetime.date.today())
 [, ]
 }}}

 {{{
 >>> TestBase.objects.exclude(test_field__lt =
 datetime.date.today()).query.as_sql()
 ('SELECT `signets_testbase`.`id`, `signets_testbase`.`test_field` FROM
 `signets_testbase` WHERE NOT ((`signets_testbase`.`test_field` < %s  AND
 NOT (`signets_testbase`.`test_field` IS NULL)))', ('2010-10-08',))
 >>> TestDerived.objects.exclude(test_field__lt =
 datetime.date.today()).query.as_sql()
 ('SELECT `signets_testbase`.`id`, `signets_testbase`.`test_field`,
 `signets_testderived`.`testbase_ptr_id` FROM `signets_testderived` INNER
 JOIN `signets_testbase` ON (`signets_testderived`.`testbase_ptr_id` =
 `signets_testbase`.`id`) WHERE NOT (`signets_testbase`.`test_field` < %s
 )', ('2010-10-08',))
 }}}

-- 
Ticket URL: 
Django 
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 django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.