Opened 3 years ago

Closed 3 years ago

Last modified 3 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 3 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 3 years ago by Ingo Klöcker

Description: modified (diff)

comment:2 Changed 3 years ago by Tim Graham

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Regression in 1bc249c2a67c24fcd28436c85388eff1d826e305.

A test to reproduce is attached.

comment:3 Changed 3 years ago by Tim Graham

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

Changed 3 years ago by Tim Graham

Attachment: 28047-test.diff added

comment:4 Changed 3 years ago by Tim Graham

Has patch: set

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

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 Changed 3 years ago by Tim Graham <timograham@…>

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