Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#9968 closed (fixed)

filter/exclude are broken on OneToOneField with primary_key=True

Reported by: gregoire Owned by: Malcolm Tredinnick
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:

Description

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.

Change History (4)

comment:1 Changed 8 years ago by Malcolm Tredinnick

Needs documentation: unset
Needs tests: unset
Owner: changed from nobody to Malcolm Tredinnick
Patch needs improvement: unset
Status: newassigned

comment:2 Changed 8 years ago by Jacob

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:3 Changed 8 years ago by Malcolm Tredinnick

Resolution: fixed
Status: assignedclosed

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

comment:4 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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