Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#25972 closed Bug (fixed)

Filtering a ForeignObject with 'isnull' lookup fails in Django 1.9

Reported by: Tomo Otsuka Owned by: nobody
Component: Database layer (models, ORM) Version: 1.9
Severity: Release blocker Keywords: ForeignObject
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Introduced by this PR: https://github.com/django/django/pull/4036

For example, with the following models:

from django.db import models
class Author(models.Model):
    id = models.IntegerField()
    name = models.CharField()
    class Meta:
        app_label = 'foo'

class Book(models.Model):
    author_id = models.IntegerField()
    author_name = models.CharField()
    author = models.ForeignObject(Author, models.CASCADE, ['author_id', 'author_name'], ['id', 'name'])
    class Meta:
        app_label = 'foo'

Running the following filter:

Book.objects.filter(author__isnull=True).query.__str__()

Will result in:

AttributeError: 'MultiColSource' object has no attribute 'as_sql'
> .../django/db/models/sql/compiler.py(366)compile()
    365         else:
--> 366             sql, params = node.as_sql(self, self.connection)
    367         if select_format and not self.subquery:

Change History (5)

comment:1 Changed 4 years ago by Tomo Otsuka

Has patch: set

comment:3 Changed 4 years ago by Tim Graham

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:4 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 8b6974a:

Fixed #25972 -- Restored support for the isnull lookup with ForeignObject.

comment:5 Changed 4 years ago by Tim Graham <timograham@…>

In bc5eed8f:

[1.9.x] Fixed #25972 -- Restored support for the isnull lookup with ForeignObject.

Backport of 8b6974a6857bdc48ad50bf21527b840c27648891 from master

Note: See TracTickets for help on using tickets.
Back to Top