[Django] #30537: ORM: ForeignKey: inconsistent handling of referenced obj. id

4 views
Skip to first unread message

Django

unread,
Jun 2, 2019, 11:42:52 AM6/2/19
to django-...@googlegroups.com
#30537: ORM: ForeignKey: inconsistent handling of referenced obj. id
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
AliakseiMi |
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) | Keywords: ORM, ForeignKey,
Severity: Normal | NOT NULL constraint, inconsistency
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30537>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 2, 2019, 11:44:58 AM6/2/19
to django-...@googlegroups.com
#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

unread,
Jun 3, 2019, 1:20:55 AM6/3/19
to django-...@googlegroups.com
#30537: ForeignKey: inconsistent handling of referenced obj. id.
-------------------------------------+-------------------------------------
Reporter: Aliaksei | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution: duplicate

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
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #28147.

--
Ticket URL: <https://code.djangoproject.com/ticket/30537#comment:2>

Reply all
Reply to author
Forward
0 new messages