klipstein/dojango — Issue #47: 47 - ObjectArg not usable in Stores 
Author: klipstein
Created: 2011-11-06 12:59:29+00:00
State: open

The _build_args method in dojango/data/modelstore/methods.py seems to
overwrite self.args in the StoreMethod used in the StoreField:

args = []
for arg in self.args:
try:
arg = self.field.proxied_args.get(arg.__name__, arg)
except AttributeError: # No __name__ attr on the arg
pass
args.append(arg)
self.args = args

This is a problem if the ObjectArg is used, because ObjectArg will only
match in the first iteration over the objects to be serialized, in the
other iterations, the ObjectArg has already been overwritten by the object
from in the first iteration and thus no replacement takes place..

My store is set up like:

class TestStore(Store):
test1 = StoreField(get_value=StoreMethod('get_test1', ObjectArg))

def get_test1(self, obj):
print obj

I had to apply the following in order to restore the old args:

Index: data/modelstore/methods.py
===================================================================
--- data/modelstore/methods.py (revision 255)
+++ data/modelstore/methods.py (working copy)
@@ -85,8 +85,11 @@
""" Builds the arguments and returns the value of the method call
"""

+ old_args = self.args
self._build_args()
- return self.get_value()
+ value = self.get_value()
+ self.args = old_args
+ return value

def _build_args(self):
""" Builds the arguments to be passed to the given method

Original link: http://code.google.com/p/dojango/issues/detail?id=47