#29226: @modify_settings append/remove/prepend is affected by dictionary order
-------------------------------------+-------------------------------------
     Reporter:  Manuel Kaufmann      |                    Owner:
                                     |  benjaoming
         Type:  Uncategorized        |                   Status:  assigned
    Component:  Testing framework    |                  Version:  2.0
     Severity:  Normal               |               Resolution:
     Keywords:  tests,               |             Triage Stage:  Accepted
  modify_settings                    |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by benjaoming):

 * owner:  nobody => benjaoming
 * status:  new => assigned
 * type:  Cleanup/optimization => Uncategorized


Comment:

 Hi!

 Sounds like a time-consuming issue for those who might encounter it. I
 agree with Tim that hopefully someone would think twice about this, but
 having dealt with issues related to dict key ordering myself, I have to
 admit that you get it wrong sometimes.

 Also, the example in the docs would directly lead to the issue, except
 that it does append/remove/prepend the same items, but it stills seems
 like it would easily misguide someone to do that:
 
https://docs.djangoproject.com/en/2.0/topics/testing/tools/#django.test.SimpleTestCase.modify_settings

 The solution that Markus and I just discussed was that you can A) use
 `OrderedDict` or B) add `modify_settings` twice like this:

 {{{#!python

 # ...
 @modify_settings(MIDDLEWARES={
     'remove': [
         '4',
         '5',
     ],
 })
 @modify_settings(MIDDLEWARES={
     'append': [
         'MyOwnMiddlewareHere',
         '4',
         '5',
     ],
 })

 }}}

 Two suggestions:

 1. Updating the (misguiding) example that does the above without
 elaborating lots about why it's applied several times:
 
https://docs.djangoproject.com/en/2.0/topics/testing/tools/#django.test.SimpleTestCase.modify_settings
 1. Add a warning box about doing append+reject on the same items (re-
 ordering)

 As I understand Tim's comment, the latter would be a bit over the top, but
 the former could be preferable as it wouldn't complicate the docs much?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29226#comment:4>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.b2ef6d91d1f9e6c3c8de09a2c5ed98d5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to