Don't use mutables as default args

Bug #1327473 reported by ChangBo Guo(gcb)
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Low
Ivan Kolodyazhny
OpenStack Compute (nova)
Fix Released
Low
ChangBo Guo(gcb)
OpenStack Heat
Fix Released
Undecided
Liusheng
neutron
Fix Released
Low
Unassigned
octavia
Fix Released
Undecided
Bertrand Lallau
oslo.messaging
Fix Released
Low
ChangBo Guo(gcb)
python-heatclient
Fix Released
Low
Liusheng

Bug Description

Passing mutable objects as default args is a known Python pitfall.
We'd better avoid this.

This is an example show the pitfall:
http://docs.python-guide.org/en/latest/writing/gotchas/

Revision history for this message
ChangBo Guo(gcb) (glongwave) wrote :
Changed in nova:
assignee: nobody → ChangBo Guo(gcb) (glongwave)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo.messaging (master)

Fix proposed to branch: master
Review: https://review.openstack.org/98569

Changed in oslo.messaging:
assignee: nobody → ChangBo Guo(gcb) (glongwave)
status: New → In Progress
Andrew Laski (alaski)
Changed in nova:
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/98339
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=0bea84ac20fe498bd08f7212a0017196c8cb0812
Submitter: Jenkins
Branch: master

commit 0bea84ac20fe498bd08f7212a0017196c8cb0812
Author: ChangBo Guo(gcb) <email address hidden>
Date: Sat Jun 7 10:49:20 2014 +0800

    Removes the use of mutables as default args

    Passing mutable objects as default args is a known Python pitfall.
    We'd better avoid this. This commit changes mutable default args with
    None, then use 'arg = arg or {}', 'arg = arg or []'. For unit code which
    doesn't use the args , just set with None. This commit also adds hacking
    check.

    Closes-Bug: #1327473
    Change-Id: I5a8492bf8ffef8e000b13b6bdfaef1968b96f816

Changed in nova:
status: In Progress → Fix Committed
Mark McLoughlin (markmc)
Changed in oslo.messaging:
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo.messaging (master)

Reviewed: https://review.openstack.org/98569
Committed: https://git.openstack.org/cgit/openstack/oslo.messaging/commit/?id=821ee096a6b1dd897892af90b47738051d0fa8f4
Submitter: Jenkins
Branch: master

commit 821ee096a6b1dd897892af90b47738051d0fa8f4
Author: ChangBo Guo(gcb) <email address hidden>
Date: Sat Jun 7 12:06:08 2014 +0800

    Removes the use of mutables as default args

    Passing mutable objects as default args is a known Python pitfall.
    We'd better avoid this.

    Change-Id: I67cc0774a65886ef9fce0b72e52157b622248a85
    Closes-Bug: #1327473

Changed in oslo.messaging:
status: In Progress → Fix Committed
Liusheng (liusheng)
Changed in cinder:
assignee: nobody → Liusheng (liusheng)
Changed in heat:
assignee: nobody → Liusheng (liusheng)
Changed in neutron:
assignee: nobody → Liusheng (liusheng)
Changed in neutron:
status: New → In Progress
Changed in cinder:
status: New → In Progress
Changed in heat:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (master)

Reviewed: https://review.openstack.org/103707
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=5541f4390333aae07879d9996c72f2095eda19a3
Submitter: Jenkins
Branch: master

commit 5541f4390333aae07879d9996c72f2095eda19a3
Author: liu-sheng <email address hidden>
Date: Tue Jul 1 10:58:22 2014 +0800

    Use None instead of mutables in method params defaults

    Mutables in the method params defaults might cause errors and
    that's why it's anti-pattern in most of the cases and should be
    removed.

    Change-Id: I8bc284f12ce72082a0482410ec2c20c2fc087a4b
    Closes-Bug: #1327473

Changed in heat:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-heatclient (master)

Fix proposed to branch: master
Review: https://review.openstack.org/104423

Changed in python-heatclient:
assignee: nobody → Liusheng (liusheng)
status: New → In Progress
Kyle Mestery (mestery)
Changed in neutron:
milestone: none → juno-2
importance: Undecided → Low
Revision history for this message
Elena Ezhova (eezhova) wrote :
Revision history for this message
Mark McClain (markmcclain) wrote :

I question the need for this . While mutable arguments can be a potential source for issues, an outright ban seems like a terrible idea. There are valid patterns (i.e. argument designed to intentionally accumulate or default read-only empty iterables). Reviewers should be be able to judge whether the usage of the the arguments is proper versus installing a blanket ban.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on neutron (master)

Change abandoned by liusheng (<email address hidden>) on branch: master
Review: https://review.openstack.org/103713

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on cinder (master)

Change abandoned by liusheng (<email address hidden>) on branch: master
Review: https://review.openstack.org/103756

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on python-heatclient (master)

Change abandoned by liusheng (<email address hidden>) on branch: master
Review: https://review.openstack.org/104423

Changed in cinder:
assignee: Liusheng (liusheng) → Ivan Kolodyazhny (e0ne)
Kyle Mestery (mestery)
Changed in neutron:
milestone: juno-2 → none
Jay Bryant (jsbryant)
Changed in cinder:
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (master)

Reviewed: https://review.openstack.org/106872
Committed: https://git.openstack.org/cgit/openstack/cinder/commit/?id=1cfb7da7ce3f93765ba2e267897b5b7825a0ba75
Submitter: Jenkins
Branch: master

commit 1cfb7da7ce3f93765ba2e267897b5b7825a0ba75
Author: Ivan Kolodyazhny <email address hidden>
Date: Tue Jul 15 00:13:54 2014 +0300

    Use immutable default values for args

    Default mutable values (e.g. arg1=[], arg2={}) could have side effects
    in Python. So using None as a default value is safer.

    Added hacking checks for default mutable args.

    Closes: bug #1327473

    Change-Id: I7055e534b91df794550de6c3b243324e582d4430

Changed in cinder:
status: In Progress → Fix Committed
Changed in nova:
milestone: none → juno-2
status: Fix Committed → Fix Released
Changed in heat:
milestone: none → juno-2
status: Fix Committed → Fix Released
Changed in oslo.messaging:
milestone: none → juno-2
status: Fix Committed → Fix Released
Changed in cinder:
milestone: none → juno-2
status: Fix Committed → Fix Released
Changed in neutron:
assignee: Liusheng (liusheng) → Kevin Benton (kevinbenton)
Thierry Carrez (ttx)
Changed in nova:
milestone: juno-2 → 2014.2
Thierry Carrez (ttx)
Changed in cinder:
milestone: juno-2 → 2014.2
Thierry Carrez (ttx)
Changed in heat:
milestone: juno-2 → 2014.2
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.openstack.org/121403
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=bc61dd0e3493b0e5c5b2e0e1e9d16b65532c6c4a
Submitter: Jenkins
Branch: master

commit bc61dd0e3493b0e5c5b2e0e1e9d16b65532c6c4a
Author: Kevin Benton <email address hidden>
Date: Sun Sep 14 01:53:52 2014 -0700

    Remove default dictionary from function def

    Removes an unnecessary dictionary created in the default
    parameters definition for the execute function in ip_lib.

    Partial-Bug: #1327473
    Change-Id: I9b60e87d1043aa67a14675dad2185395df940301

Changed in neutron:
assignee: Kevin Benton (kevinbenton) → nobody
Jonathan Bell (jbell-f)
Changed in neutron:
assignee: nobody → Jonathan Bell (jbell-f)
Changed in python-heatclient:
importance: Undecided → Low
status: In Progress → Fix Released
Changed in octavia:
assignee: nobody → Bertrand Lallau (bertrand-lallau)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to octavia (master)

Fix proposed to branch: master
Review: https://review.openstack.org/240455

Changed in octavia:
status: New → In Progress
Revision history for this message
Reedip (reedip-banerjee-deactivatedaccount) wrote :

Changing the user as there is no progress for a long time

Changed in neutron:
assignee: Jonathan Bell (jbell-f) → Reedip (reedip-banerjee)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

Fix proposed to branch: master
Review: https://review.openstack.org/240748

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron-lbaas (master)

Fix proposed to branch: master
Review: https://review.openstack.org/240756

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on neutron (master)

Change abandoned by Reedip (<email address hidden>) on branch: master
Review: https://review.openstack.org/240748

Revision history for this message
Reedip (reedip-banerjee-deactivatedaccount) wrote :
Changed in neutron:
assignee: Reedip (reedip-banerjee) → nobody
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron-lbaas (master)

Reviewed: https://review.openstack.org/240756
Committed: https://git.openstack.org/cgit/openstack/neutron-lbaas/commit/?id=0aac2d029a7ed9bff903a00a4ab194e277dfe06c
Submitter: Jenkins
Branch: master

commit 0aac2d029a7ed9bff903a00a4ab194e277dfe06c
Author: Reedip Banerjee <email address hidden>
Date: Mon Nov 2 10:24:44 2015 +0530

    Avoiding usage of mutables as default arguments

    Using Mutables objects as default arguments in function
    definition is a known Python pitfall. This patch fixes
    the issue in neutron-lbaas.

    Change-Id: Idb1cccbebec5dfedde04ee474036e67569406caa
    Closes-Bug: #1327473

Changed in neutron:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron-lbaas (stable/liberty)

Fix proposed to branch: stable/liberty
Review: https://review.openstack.org/242534

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to octavia (master)

Reviewed: https://review.openstack.org/240455
Committed: https://git.openstack.org/cgit/openstack/octavia/commit/?id=76e1e02e15bf83a7ac4ca01bfb2f6665975829c9
Submitter: Jenkins
Branch: master

commit 76e1e02e15bf83a7ac4ca01bfb2f6665975829c9
Author: Bertrand Lallau <email address hidden>
Date: Fri Oct 30 08:11:46 2015 +0100

    Removes the use of mutables as default args

    Passing mutable objects as default args is a known Python pitfall.
    We'd better avoid this. This commit changes mutable default args with
    None, then use 'arg = arg or {}', 'arg = arg or []'. For unit code which
    doesn't use the args , just set with None. This commit also adds hacking
    check.

    Change-Id: Ib4f195c9c00ca2c49579f9d62648bff7c8109fcf
    Closes-Bug: #1327473

Changed in octavia:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron-lbaas (stable/liberty)

Reviewed: https://review.openstack.org/242534
Committed: https://git.openstack.org/cgit/openstack/neutron-lbaas/commit/?id=a9ad175f0be9b34287d41fdb76ee6a103e328bb6
Submitter: Jenkins
Branch: stable/liberty

commit a9ad175f0be9b34287d41fdb76ee6a103e328bb6
Author: Reedip Banerjee <email address hidden>
Date: Mon Nov 2 10:24:44 2015 +0530

    Avoiding usage of mutables as default arguments

    Using Mutables objects as default arguments in function
    definition is a known Python pitfall. This patch fixes
    the issue in neutron-lbaas.

    Change-Id: Idb1cccbebec5dfedde04ee474036e67569406caa
    Closes-Bug: #1327473
    (cherry picked from commit 0aac2d029a7ed9bff903a00a4ab194e277dfe06c)

tags: added: in-stable-liberty
Revision history for this message
Thierry Carrez (ttx) wrote : Fix included in openstack/neutron-lbaas 8.0.0.0b1

This issue was fixed in the openstack/neutron-lbaas 8.0.0.0b1 development milestone.

Changed in neutron:
status: Fix Committed → Fix Released
Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/neutron-lbaas 7.0.1

This issue was fixed in the openstack/neutron-lbaas 7.0.1 release.

Changed in octavia:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.