Opened 5 years ago

Last modified 5 years ago

#30537 closed Bug

ORM: ForeignKey: inconsistent handling of referenced obj. id — at Version 1

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 (1)

comment:1 by Aliaksei, 5 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top