carolinux / gdata-python-client

Automatically exported from code.google.com/p/gdata-python-client
0 stars 1 forks source link

Using mutable types for argument defaults.. #511

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Import gdata.analytics.client
2. Create any Query object from this module.
3. Update the object's query attribute
4. Create another Query object.
5. Notice the query remembers arguments from the first instance.

What is the expected output? What do you see instead?
Each object does not use a global query value.

What version of the product are you using?
It exists in the current source (Mar 31, 2011).

Please provide any additional information below.
You should not be declaring default arguments of a function with mutable types. 
 For example, looking at class gdata.analytics.client.DataFeedQuery, you define 
the constructor using __init__(self, query={}, **kwargs).  The query={} is the 
problem here.  It will only be instantiated once.  You should really be 
defining your constructor like the example below.  This bug looks like it 
exists all over the gdata.client code.  I did not check any other modules.

def __init__(self, query=None, **kwargs):
    self.query = query or {}
    gdata.client.GDQuery(self, **kwargs)

Original issue reported on code.google.com by mjs7...@gmail.com on 31 Mar 2011 at 9:59

GoogleCodeExporter commented 9 years ago

Original comment by afs...@google.com on 7 Oct 2011 at 12:23