Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#24495 closed Cleanup/optimization (fixed)

Allow unsaved objects in ForeignKey check to be bypassed

Reported by: Karl Hobley Owned by: nobody
Component: Database layer (models, ORM) Version: 1.8beta2
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Karl Hobley)

Hi everyone,

https://code.djangoproject.com/ticket/10811 implements a new check to prevent unsaved objects being set on a ForeignKey field.

A project I'm upgrading to Django 1.8 (Wagtail CMS/django-modelcluster) relies on this behaviour (for generating previews of pages without having to save them to the database. Pages can have other unsaved objects such as links or images linked to them).

See: https://github.com/torchbox/django-modelcluster#django-modelcluster

Unfortunately, this isn't an easy problem to solve without a small change to Django....

Proposed solution

Allow a flag to be specified on a subclass of ForeignKey which allows this check to be bypassed.

PR: https://github.com/django/django/pull/4334

django-modelcluster uses a subclass of ForeignKey called "ParentalKey". In Wagtail, all of the "child models" (eg, page links, images, etc) are linked to their Page model using a ParentalKey.

Setting this flag on the ParentalKey class fixes this issue: https://github.com/kaedroho/django-modelcluster/commit/915dc7e1cfc2462c2068ab9e9a334a7197935c7d

Change History (8)

comment:1 by Karl Hobley, 9 years ago

Description: modified (diff)

comment:2 by Tim Graham, 9 years ago

Needs documentation: set
Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:3 by Tim Graham, 9 years ago

Needs documentation: unset
Patch needs improvement: set

comment:4 by Tim Graham, 9 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:5 by Tim Graham, 9 years ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:6 by Tim Graham, 9 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:7 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 81e1a35:

Fixed #24495 -- Allowed unsaved model instance assignment check to be bypassed.

comment:8 by Tim Graham <timograham@…>, 9 years ago

In a8c53041:

[1.8.x] Fixed #24495 -- Allowed unsaved model instance assignment check to be bypassed.

Backport of 81e1a35c364e5353d2bf99368ad30a4184fbb653 from master

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