Opened 8 years ago

Last modified 7 years ago

#27846 closed Bug

refresh_from_db() does not create "soft links" on model_instances that are pointed to by another model's OneToOneField — at Version 2

Reported by: Keith Hostetler Owned by: nobody
Component: Database layer (models, ORM) Version: 1.10
Severity: Normal Keywords: refresh_from_db OneToOneField
Cc: Andrey Fedoseev, Berker Peksag Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Keith Hostetler)

Sorry for the poor summary, it is difficult to explain in words. I have a project to demo this bug attached to this ticket, but I will try to explain the bug anyway in steps and the setup.

Setup:

  • 2 models (A and B)
  • B has a OneToOne to A
  • Both A and B have a field (ie TextField)
  • Setup either a signal or override save() for A to update B's TextField to equal that of A's on save() or post_save for signals

Steps:

  • Create instance of A
  • Get another copy of the instance of A via A.objects.get()
  • Create instance of B using the copy of the instance of A
  • Do refresh_from_db() on original instance of A
  • Try to access B from A

The project I have provided is a slim version of this problem that demonstrates it with signals, overriden save(), and basic set and save inside the test. The basic set and save works, but the other two fail when using the above steps. Run the test suite to see.

Change History (3)

by Keith Hostetler, 8 years ago

comment:1 by Keith Hostetler, 8 years ago

Type: UncategorizedBug

comment:2 by Keith Hostetler, 8 years ago

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