Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

47 - ObjectArg not usable in Stores #47

Open
klipstein opened this issue Nov 6, 2011 · 0 comments
Open

47 - ObjectArg not usable in Stores #47

klipstein opened this issue Nov 6, 2011 · 0 comments

Comments

@klipstein
Copy link
Owner

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant