Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24418 closed Bug (fixed)

refresh_from_db is breaking on null foreign keys — at Version 6

Reported by: Johannes Lerch Owned by: nobody
Component: Database layer (models, ORM) Version: 1.8alpha1
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Johannes Lerch)

If i try to call refresh_from_db on a model instance that has a foreignkey set to null, i get an error:

(stacktrace was removed after ticket was resolved)

here rel_instance is assigned:
https://github.com/django/django/blob/stable/1.8.x/django/db/models/base.py#L630

if it is None (foreignkey not set, as it is nullable in this model) the getattr function will complain that it can not get 'id' from 'NoneType'

Change History (7)

comment:1 by Tim Graham, 10 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Reproduced with the attached test.

by Tim Graham, 10 years ago

Attachment: 24418-test.diff added

comment:2 by Claude Paroz, 10 years ago

Has patch: set

comment:3 by Simon Charette, 10 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Claude Paroz <claude@…>, 10 years ago

Resolution: fixed
Status: newclosed

In 5cf96b49e43daea6d4a0ba1c80c45e90c74f4e47:

Fixed #24418 -- Prevented crash in refresh_from_db with null fk

Thanks Johannes Lerch for the report, Tim Graham for the test case,
and Simon Charette for the review.

comment:5 by Claude Paroz <claude@…>, 10 years ago

In b825ec38c1e16a271c69694562963eadbe0c6352:

[1.8.x] Fixed #24418 -- Prevented crash in refresh_from_db with null fk

Thanks Johannes Lerch for the report, Tim Graham for the test case,
and Simon Charette for the review.
Backport of 5cf96b49e4 from master.

comment:6 by Johannes Lerch, 10 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top