#24487 closed Bug (wontfix)
Need for some retrocompatibility guidance for devs, on new OrderedDict usage
Reported by: | pascal chambon | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The change from SortedDict to OrderedDict in django1.7 was not a drop-in replacement, not only because several libs relied on the "hackish" keyOrder to sort field, but also because the methods below have disappeared, breaking libs (liek userprofile related stuffs) that made good use of them :
insert(index, key, value) Inserts the key, value pair before the item with the given index." value_for_index(index) Returns the value of the item at the given zero-based index.
Wouldn't it be helpful to add back these methods, in a subclass of OrderedDict ? Or to provide some guidance on how people are supposed to dynamically actiavte/deactivation form fields, now ?
It's unclear if completely replacing "myform.fields" with a new ordereddict, to achieve this, might be harmful.
Attachments (1)
Change History (8)
comment:1 by , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 10 years ago
These SortedDict methods were alas documented (https://docs.djangoproject.com/en/1.6/ref/utils/#module-django.utils.datastructures), that's why I fear a bunch of libs using dynamic forms may have relied on them.
Nice to see this field ordering API, I guess it'll prevent hacks in most cases.
Concerning the need to dynamically insert/remove the fields present in v1.7 forms (I have some needs like this for complex forms, checking for authentications at runtime), I'm not sure about the way to go, maybe using declarative Forms is not suited for that, and it'd be better to dynamically build form classes, than to rely on their init operations ?
comment:3 by , 10 years ago
Oh, the SortedDict method deprecation should have been documented in the 1.5 release notes. If you care to draft a patch with upgrade suggestions, I'll be happy to review it.
It should still be possible to order fields using OrderedDict
in 1.7/1.8 until the nicer API arrives. See PasswordChangeForm for an example in Django itself.
by , 10 years ago
Attachment: | 0001-Add-guidance-for-the-disappearance-of-SortedDict.patch added |
---|
Doc update to workaround the disappearance of SortedDict
Unfortunately, customizing form field order using
SortedDict
isn't a documented solution so users are on there on when using private APIs like that (similarly the methods ofSortedDict
you mentioned aren't documented). However, I just committed an official API for customizing form field ordering in #5986 for 1.9, so hopefully that helps.