Opened 6 months ago

Closed 6 months 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 Changed 6 months ago by Aliaksei

Description: modified (diff)

comment:2 Changed 6 months ago by felixxm

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