#30537: ORM: ForeignKey: inconsistent handling of referenced obj. id
-------------------------------------+-------------------------------------
Reporter: AliakseiMi | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM, ForeignKey, | Triage Stage:
NOT NULL constraint, | Unreviewed
inconsistency |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by AliakseiMi:
Old description:
> In short: if referenced obj. is saved after attaching to a referencing
> obj. its id field (i.e. ''<refrerenced_obj>''_id) there remains None.
>
> In details:
>
> {{{
> class ReferencedObj(Model):
> ...
>
> class ReferencingObj(Model):
>
> referenced_obj = ForeignKey(ReferencedObj)
> ...
>
> x = ReferencedObj()
> y = ReferencingObj()
>
> y.referenced_obj = x
>
> x.save()
>
> y.save() -----→ NOT NULL constraint failed:
> ..._referencingobj.referenced_obj_id
> }}}
New description:
In short: if referenced obj. is saved after attaching to a referencing
obj. its id field (i.e. ''<refrerenced_obj>''_id) there remains None.
In details:
{{{
class ReferencedObj(Model):
...
class ReferencingObj(Model):
referenced_obj = ForeignKey(ReferencedObj)
...
x = ReferencedObj()
y = ReferencingObj()
y.referenced_obj = x
x.save()
y.save() -----→ NOT NULL constraint failed:
..._referencingobj.referenced_obj_id
}}}
Thats happens because **referenced_obj_id** field is not bound to the
underlying **referenced_obj.id**
--
--
Ticket URL: <https://code.djangoproject.com/ticket/30537#comment:1>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.f07a68b0eb84ac9061c57747fd141e60%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.