Opened 6 years ago

Closed 5 years ago

Last modified 3 years ago

#9968 closed (fixed)

filter/exclude are broken on OneToOneField with primary_key=True

Reported by: gregoire Owned by: mtredinnick
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: gregoire@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I would expect the following test to work :

from django.db import models

class Test(models.Model):
    >>> Test.objects.create()
    <Test: Test object>
class Test_A(models.Model):
    >>> Test.objects.filter(test_a=None)
    [<Test: Test object>]
    >>> Test.objects.exclude(test_a=None)
    model = models.OneToOneField(Test, primary_key=True)
class Test_B(models.Model):
    >>> Test.objects.filter(test_b=None)
    [<Test: Test object>]
    >>> Test.objects.exclude(test_b=None)
    model = models.OneToOneField(Test)

The only difference between Test_A and Test_B is the primary_key set on teh OneToOneField.

Test_A is broken : wrong result when using filter(), IndexError exception when using exclude()

Tested on r9701.

Attachments (0)

Change History (4)

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to mtredinnick
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 5 years ago by jacob

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed in r9979 (I made a typo in the commit message).

comment:4 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.