#25715 closed Bug (fixed)
refresh_from_db fails to update null'ed ForeignKeys
Description ¶
I have User and Org models, with User having a ForeignKey to Org:
org = models.ForeignKey('Org', null=True, blank=True, on_delete=models.SET_NULL)
If I delete an Org instance then refresh the User instance, then user.org_id is cleared as expected, but user.org still references the deleted instance:
org = create_org() user = create_user(org) org.delete() user.refresh_from_db() self.assertIsNone(user.org_id) # Works! self.assertIsNone(user.org) # Fails!
Change History (7)
comment:1 by , 9 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Severity: | Normal → Release blocker |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 9 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
@andersonresende, sorry to take this one if you made any progress on it, but I wanted to make sure it's fixed for the next 1.8.x release. Feel free to review my patch if you can.
comment:4 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
on_delete=models.SET_NULL
in theForeignKey
seems to be the important part of reproducing this.