#11905: modelform_factory returns a broken form when given wrong value for
fields
-------------------------------+--------------------------------------------
Reporter: ben | Owner: copelco
Status: new | Milestone: 1.3
Component: Forms | Version: 1.1
Resolution: | Keywords: modelform_factory, modelform,
fields
Stage: Accepted | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
-------------------------------+--------------------------------------------
Comment (by copelco):
Checking for unknown fields in
[http://code.djangoproject.com/browser/django/trunk/django/forms/models.py#L153
fields_for_model] will break some existing functionality:
1. django.contrib.auth uses a custom
[http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/admin.py#L71
form] for user creation that passes invalid fields (password1 and
password2) to fields_for_model.
2. If a declarative field is listed in !ModelForm._meta.fields (as
described [http://docs.djangoproject.com/en/dev/topics/forms/modelforms
/#overriding-the-default-field-types-or-widgets here]), but is not an
actual field of the Model, an error will be raised with this change when
it previously succeeded. Current tests (like this
[http://code.djangoproject.com/browser/django/trunk/tests/modeltests/model_forms/models.py#L1546
one]) will fail with this issue.
To test this, I decided to raise a !FieldError in fields_for_model when a
passed field is not part of the related model. The diff can be found
[http://github.com/copelco/django/commit/fd9e793e4db822d5f78ce323cb72c4f7c8050f03
here]. I'd be happy to attempt a fix at both the auth and declarative
field issues, but I'd like to get some feedback first. Any thoughts?
--
Ticket URL: <http://code.djangoproject.com/ticket/11905#comment:8>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.