Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#28047 closed Bug (fixed)

QuerySet.filter() using the name of a OneToOneField primary key crashes

Reported by: Thierry Bastian Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
Severity: Release blocker Keywords: regression
Cc: 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 Ingo Klöcker)

I have this (simplified)

from django.db import models

class Foo(models.Model):
    class Meta:
        app_label = 'inventory'
    pass

class Bar(models.Model):
    class Meta:
        app_label = 'inventory'
    foo = models.OneToOneField(Foo, primary_key=True, on_delete=models.CASCADE)

Of course you need an app named inventory. But just use this and try to create a query set like this:

Bar.objects.filter(foo__in=Foo.objects.all())

Obviously I had different criteria.

Creating that query set says:
"django.core.exceptions.FieldError: Cannot resolve keyword 'foo' into field. Choices are: bar, id"

That was working just fine in Django 1.10

Attachments (1)

28047-test.diff (523 bytes ) - added by Tim Graham 8 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Ingo Klöcker, 8 years ago

Description: modified (diff)

comment:2 by Tim Graham, 8 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Regression in 1bc249c2a67c24fcd28436c85388eff1d826e305.

A test to reproduce is attached.

comment:3 by Tim Graham, 8 years ago

Summary: Regression in query set against 1.10QuerySet.filter() using the name of a OneToOneField primary key crashes

by Tim Graham, 8 years ago

Attachment: 28047-test.diff added

comment:4 by Tim Graham, 8 years ago

Has patch: set

comment:5 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In fce78271:

Fixed #28047 -- Fixed QuerySet.filter() crash when it uses the name of a OneToOneField pk.

Regression in 1bc249c2a67c24fcd28436c85388eff1d826e305.

comment:6 by Tim Graham <timograham@…>, 8 years ago

In 8a13cddc:

[1.11.x] Fixed #28047 -- Fixed QuerySet.filter() crash when it uses the name of a OneToOneField pk.

Regression in 1bc249c2a67c24fcd28436c85388eff1d826e305.

Backport of fce782710160420d5c963bb33a6646542d91f40c from master

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