Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#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)

0001-Add-guidance-for-the-disappearance-of-SortedDict.patch (1.6 KB ) - added by pascal chambon 10 years ago.
Doc update to workaround the disappearance of SortedDict

Download all attachments as: .zip

Change History (8)

comment:1 by Tim Graham, 10 years ago

Resolution: wontfix
Status: newclosed

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 of SortedDict 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.

comment:2 by pascal chambon, 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 Tim Graham, 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 pascal chambon, 10 years ago

Doc update to workaround the disappearance of SortedDict

comment:4 by Tim Graham <timograham@…>, 10 years ago

In c5c87511:

Refs #24487 -- Added upgrade tips about removal of SortedDict.

Thanks Pascal Chambon for the initial patch.

comment:5 by Tim Graham <timograham@…>, 10 years ago

In ddb95d6d:

[1.8.x] Refs #24487 -- Added upgrade tips about removal of SortedDict.

Thanks Pascal Chambon for the initial patch.

Backport of c5c8751147d41913a05e86097ea29ccc9fc2e5be from master

comment:6 by Tim Graham <timograham@…>, 10 years ago

In 11892713:

[1.7.x] Refs #24487 -- Added upgrade tips about removal of SortedDict.

Thanks Pascal Chambon for the initial patch.

Backport of c5c8751147d41913a05e86097ea29ccc9fc2e5be from master

comment:7 by pascal chambon, 10 years ago

Thanks

Note: See TracTickets for help on using tickets.
Back to Top