Re: [Django] #36151: Non-editable FieldError raised when using a GenericForeignKey on a form.

11 views
Skip to first unread message

Django

unread,
Jan 28, 2025, 9:34:00 AM1/28/25
to django-...@googlegroups.com
#36151: Non-editable FieldError raised when using a GenericForeignKey on a form.
--------------------------------------+------------------------------------
Reporter: James Pic | Owner: (none)
Type: Bug | Status: new
Component: contrib.contenttypes | Version: 5.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Sarah Boyce):

* needs_docs: 0 => 1
* needs_tests: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36151#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 28, 2025, 12:04:33 PM1/28/25
to django-...@googlegroups.com
#36151: Non-editable FieldError raised when using a GenericForeignKey on a form.
-------------------------------------+-------------------------------------
Reporter: James Pic | Owner: James Pic
Type: Bug | Status: assigned
Component: | Version: 5.1
contrib.contenttypes |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* owner: (none) => James Pic
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36151#comment:7>

Django

unread,
Jan 28, 2025, 2:34:42 PM1/28/25
to django-...@googlegroups.com
#36151: Non-editable FieldError raised when using a GenericForeignKey on a form.
-------------------------------------+-------------------------------------
Reporter: James Pic | Owner: James Pic
Type: Bug | Status: assigned
Component: | Version: 5.1
contrib.contenttypes |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by James Pic):

pushed test and docs, keeping the current behaviour and allowing to go
back to the previous one with explicit editable=True
we can also restore the previous behaviour with editable=True by default,
but I'm not convinced it was intended, given the hardcoding on
editable=False in the said commit
although, perhaps the author just reproduced what he saw: a class
attribute of editable=False
https://github.com/django/django/commit/6002df06713cb0a7050432263527a25754190c27
#diff-76b33afd71c30afb749a0de312cfe4a4578d78abae84a9d5db06388a4b1bc454L39
I'm willing to update the patch whenever a design decision is taken by
authority though
--
Ticket URL: <https://code.djangoproject.com/ticket/36151#comment:8>

Django

unread,
Jan 29, 2025, 3:58:05 AM1/29/25
to django-...@googlegroups.com
#36151: Non-editable FieldError raised when using a GenericForeignKey on a form.
-------------------------------------+-------------------------------------
Reporter: James Pic | Owner: James Pic
Type: Bug | Status: assigned
Component: | Version: 5.1
contrib.contenttypes |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1
* needs_tests: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/36151#comment:9>

Django

unread,
Jan 31, 2025, 1:59:42 PM1/31/25
to django-...@googlegroups.com
#36151: Non-editable FieldError raised when using a GenericForeignKey on a form.
-------------------------------------+-------------------------------------
Reporter: James Pic | Owner: James Pic
Type: Bug | Status: closed
Component: | Version: 5.1
contrib.contenttypes |
Severity: Release blocker | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => wontfix
* status: assigned => closed

Comment:

Have considered and discussed this quite a bit

[https://docs.djangoproject.com/en/5.1/ref/contrib/contenttypes/#django.contrib.contenttypes.fields.GenericForeignKey
GenericForeignKey] explicitly documents that they are not included on
`ModelForms`. Part of the reason is that a `GenericForeignKey` would need
a custom form field (with a custom widget), which is not currently defined
on the `GenericForeignKey.formfield()` and would also be a little
complicated (it doesn't make sense to have both this field and the
underlying `ct_field` and `fk_field` defined on the field).

Hence, it makes sense for a custom `EditableGenericForeignKey` field to be
defined in someone's project which uses the custom field widget in
`formfield` and sets the field as `editable=True` (and likely sets the
`ct_field` and `fk_field` as `editable=False`). This is roughly suggested
as a solution in the [https://forum.djangoproject.com/t/non-editable-
error-for-a-genericforeignkey-in-an-modelform-when-updating-to-
version-5-1/35033 forum discussion].

The behavior we now have is aligned to other fields and matches our
documentation. Hence, I will update the status to `wontfix`.
--
Ticket URL: <https://code.djangoproject.com/ticket/36151#comment:10>
Reply all
Reply to author
Forward
0 new messages