Opened 10 years ago

Closed 10 years ago

#11053 closed (duplicate)

access to OneToOneField when null=True should return None instead of raising DoesNotExist

Reported by: Harm Geerts <hgeerts@…> Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


class Place(models.Model):
    name = models.CharField(max_length=50)

class UndergroundBar(models.Model):
    place = models.OneToOneField(Place, null=True)

Django behaves differently with access to the OneToOneField depending on which side of the relation is used.
Currently will return None while Place.undergroundbar raises DoesNotExist.

Attachments (1)

django-onetoonefield.patch (1.5 KB) - added by Harm Geerts <hgeerts@…> 10 years ago.

Download all attachments as: .zip

Change History (2)

Changed 10 years ago by Harm Geerts <hgeerts@…>

Attachment: django-onetoonefield.patch added

comment:1 Changed 10 years ago by Harm Geerts <hgeerts@…>

Resolution: duplicate
Status: newclosed

I thought I had looked over existing tickets but it seems I missed one.
dupe of #10227

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