Opened 5 years ago

Last modified 5 years ago

#24495 closed Cleanup/optimization

Allow unsaved objects in ForeignKey check to be bypassed — at Version 1

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, 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).


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.


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:

Change History (1)

comment:1 Changed 5 years ago by Karl Hobley

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