#8892: ForeignKey relation not saved as expected -------------------------------------+------------------------------------- Reporter: julien | Owner: blacklwhite Type: Bug | Status: reopened Milestone: | Component: Database layer Version: 1.0 | (models, ORM) Resolution: | Severity: Normal Triage Stage: Accepted | Keywords: Needs documentation: 0 | Has patch: 1 Patch needs improvement: 0 | Needs tests: 0 UI/UX: 0 | Easy pickings: 0 -------------------------------------+------------------------------------- Changes (by blacklwhite):
* needs_better_patch: 1 => 0 * needs_tests: 1 => 0 Comment: Thank you for your feedback. Your hint made it much more simpler to find the correct piece of code to bugfix it. And - as you said - it fits formerly as a two liner into the existing code :-) The patch will now raise an error and results in the following behaviour: {{{ >>> a = ModelA(name="a") >>> b = ModelB(name="b") >>> a.b = b ValueError: Cannot assign "<ModelB: ModelB object>": "ModelB.b" must have a primary key. }}} It does the same the reversed scenario. {{{ >>> a = ModelA(name="a") >>> b = ModelB(name="b") >>> b.a_set.add(a) }}} Is the error message ok or would it be better to append "You have to save <ModelB: ModelB object> before assignment." or something like that? Are the both tests in the right class / method? What about compatibility to people using a workaround like follows; don't considering about that? {{{ >>> a = ModelA(name="a") >>> b = ModelB(name="b") >>> a.b = b >>> print a.b.name >>> b.save() >>> a.b_id = a.b.id >>> a.save() }}} -- Ticket URL: <https://code.djangoproject.com/ticket/8892#comment:15> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.