Opened 5 years ago

Closed 5 years ago

#30537 closed Bug (duplicate)

ForeignKey: inconsistent handling of referenced obj. id.

Reported by: Aliaksei Owned by: nobody
Component: Database layer (models, ORM) Version: 2.0
Severity: Normal Keywords: ORM, ForeignKey, NOT NULL constraint, inconsistency
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Aliaksei)

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

Change History (2)

comment:1 by Aliaksei, 5 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 5 years ago

Resolution: duplicate
Status: newclosed
Summary: ORM: ForeignKey: inconsistent handling of referenced obj. idForeignKey: inconsistent handling of referenced obj. id.

Duplicate of #28147.

Note: See TracTickets for help on using tickets.
Back to Top