#26983: models.Manager query "filter(field__isnull=False)" not working in 1.10
-------------------------------------+-------------------------------------
     Reporter:  weidwonder           |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.10
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  queryset             |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by weidwonder):

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


Old description:

> models Manager:
>

> {{{
> class ModelManager(models.Manager):
>     def get_queryset(self):
>         return super(ModelManager,
> self).get_queryset().filter(parent__isnull=False)
> }}}
>
> models:
>

> {{{
> class Category(models.Model):
>     parent = models.ForeignKey('Category', to_field='slug',
> db_column='parent',
>                                max_length=32, blank=True, null=True,
>                                related_name='models')
>     name = models.CharField(max_length=50, blank=True, null=True)
>     ....
>     vehicle_models = ModelManager()
>
>     class Meta:
>         db_table = 'open_category'
>         ordering = ['pinyin']
>
> }}}
>
> query:
>
> {{{
> Category.vehicle_models.filter(slug=model_slug).values('name').query
> }}}
>
> query's sql output is:
>

> {{{
> SELECT `open_category`.`name` FROM `open_category` WHERE
> (`open_category`.`parent` IS NULL AND `open_category`.`slug` = "suteng")
> ORDER BY `open_category`.`pinyin` ASC
> }}}
>
> it should be '''`open_category`.`parent` IS NOT NULL'''

New description:

 models Manager:


 {{{
 class ModelManager(models.Manager):
     def get_queryset(self):
         return super(ModelManager,
 self).get_queryset().filter(parent__isnull=False)
 }}}

 models:


 {{{
 class Category(models.Model):
     parent = models.ForeignKey('Category', to_field='slug',
 db_column='parent',
                                max_length=32, blank=True, null=True,
                                related_name='models')
     name = models.CharField(max_length=50, blank=True, null=True)
     ....
     vehicle_models = ModelManager()

     class Meta:
         db_table = 'open_category'
         ordering = ['pinyin']

 }}}

 query:

 {{{
 Category.vehicle_models.filter(slug=model_slug).values('name').query
 }}}

 query's sql output is:


 {{{
 SELECT `open_category`.`name` FROM `open_category` WHERE
 (`open_category`.`parent` IS NULL AND `open_category`.`slug` = "suteng")
 ORDER BY `open_category`.`pinyin` ASC
 }}}

 it should be '''`open_category`.`parent` IS NOT NULL''', I downgrade
 django to 1.9.9, it works.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26983#comment:1>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.df8d83ed7eb2703fb87bef11b9ed8982%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to