#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 )
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 , 10 years ago
Description: | modified (diff) |
---|
comment:2 by , 10 years ago
Needs documentation: | set |
---|---|
Severity: | Normal → Release blocker |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:3 by , 10 years ago
Needs documentation: | unset |
---|---|
Patch needs improvement: | set |
comment:4 by , 10 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:5 by , 10 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
comment:6 by , 10 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:7 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
In 81e1a35: