Opened 6 years ago

Closed 6 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: UI/UX:

Description

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 UndergroundBar.place will return None while Place.undergroundbar raises DoesNotExist.

Attachments (1)

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

Download all attachments as: .zip

Change History (2)

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

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

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