raise TypeError on form instantiation if data/files parameter isn't a dict.
|Reported by:||ajs||Owned by:||nobody|
|Severity:||Keywords:||KeyError forms dict instantiation|
|Cc:||ajs||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
No error is thrown if a form is passed a non dict value to it's data or files parameter on instantiation.
When the form is validated a AttributeError: 'type' object has no attribute 'get' is raised.
I found it confusing that the form instantiation was ok and but somewhere in my template everything broke.
The attached patch checks that the data/files are instances of dict or django.utils.datastructures.MergeDict
if not it raises a TypeError.
Tests are included.
There are 2 issues that need to be looked at:
- passing an instance of something that behaves like a dict but isn't a subclass of dict or MergeDict, won't work with this patch applied, which I'm not really happy about but my python-fu isn't strong enough to come up with a better solution. Rewriting the patch to use getattr is a possibility.
- It might be considered an backwards incompatible change since now TypeError can be raised.
Change History (5)
Changed 5 years ago by ajs
comment:1 Changed 5 years ago by Alex
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Design decision needed