#22510: Form fields cannot have names that are present as attributes on the form ---------------------------------+-------------------------------------- Reporter: gc@… | Owner: nobody Type: Bug | Status: new Component: Forms | Version: 1.7-beta-2 Severity: Release blocker | Resolution: Keywords: | Triage Stage: Accepted Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ---------------------------------+--------------------------------------
Comment (by loic84): I've discussed this with @gcbirzan on IRC, there is indeed a regression on attributes called `media`. Since `MediaDefiningClass` monkeypatches each subclass with a `media` attribute, it effectively shadows any field called `media`. Moving the shadowing before the parent's fields discovery as suggested above would allow a single Form to have a `media` field, but that wouldn't work when inheritance is involved anyway. The problem could also manifest itself with overridden methods that would clash with a field name: {{{ Form(forms.Form): clean = forms.BooleanField() Form2(Form): def clean(self): pass }}} Options I can think of: - Backward incompatible change, care must be taken when subclassing a form not to accidentally shadow a field with a method, and a special mention for `media`. - Change the shadowing logic to use a sentinel value (e.g. `None`, or a `ShadowField` object). - A declarative class attribute to list the fields to shadow: {{{ Form(forms.Form): something = forms.CharField() Form2(Form): shadow_fields = ['something'] }}} For reference the ticket for field shadowing is #8620. -- Ticket URL: <https://code.djangoproject.com/ticket/22510#comment:6> Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/071.6910b6039ea6af7d950b0d9d2f0ec4a9%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.