Mutable objects are being used as default value of param

Bug #1330322 reported by Ghanshyam Mann
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
tempest
Fix Released
Undecided
Ghanshyam Mann

Bug Description

In many places mutable objects like list, dict are being used as default value of param.

This create issues as default values are being evaluated only during definition of function not at runtime when those are being called. And in case of mutable objects as default value, it maintain its state between function call. One function call can change the value of mutable object which reflects in another function call and can create the issue.

Those needs to be replace by taking default value as 'None' and have if else condition accordingly in function def.

Changed in tempest:
assignee: nobody → Ghanshyam Mann (ghanshyammann)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to tempest (master)

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

Changed in tempest:
status: New → In Progress
Revision history for this message
Yair Fried (yfried) wrote :

Nice catch. Did you just happened to notice this in the code, or did you see an actual bug?

Revision history for this message
Ghanshyam Mann (ghanshyammann) wrote :

No actual bug as those function are not used in such way yet to have actual bug.

Revision history for this message
Elena Ezhova (eezhova) wrote :

There already is a bug that is related to a very same problem in most of other projects, you could probably take a look at it.

https://bugs.launchpad.net/nova/+bug/1327473

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

Reviewed: https://review.openstack.org/100132
Committed: https://git.openstack.org/cgit/openstack/tempest/commit/?id=2a180b83982442275505f275ba1a4d16662e78b3
Submitter: Jenkins
Branch: master

commit 2a180b83982442275505f275ba1a4d16662e78b3
Author: Ghanshyam <email address hidden>
Date: Mon Jun 16 13:54:22 2014 +0900

    Fix "mutable" object as default value

    This patch fix the coding issue where "mutable" objects like list, dict
    are being used as default value of param.

    Current functions with mutable object as default value can create issues
    if they will be called in more random order.
    For example - first call with non default value and then with default
    value. In this case original default will be overridden by the first
    function call (as mutable object keep their state among function calls).

    This commit also add the hacking check for the same and its
    corresponding test.

    Closes-Bug: #1330322

    Change-Id: I251b316ef6d37f4b95c5e8d73a20a39005c22870

Changed in tempest:
status: In Progress → 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.