milesrichardson / ParsePy

A relatively up-to-date fork of ParsePy, the Python wrapper for the Parse.com API. Originally maintained by @dgrtwo
MIT License
515 stars 184 forks source link

Query of an object (with objectId #111

Closed hugoliv closed 9 years ago

hugoliv commented 9 years ago

Hello,

I don't know why this line seems to not working:

 client = Client.Query.get(objectId="ZnsHNCBCau")

With this error:

 File "/.../parse_rest/query.py", line 64, in get
 return self.filter(**kw).get()
 File "/.../parse_rest/query.py", line 175, in get
 results = self._fetch()
 File "/.../parse_rest/query.py", line 129, in _fetch
 self._result_cache = self._manager._fetch(**options)
 File "/.../parse_rest/query.py", line 48, in _fetch
 return [klass(**it) for it in klass.GET(uri, **kw).get('results')]
 TypeError: __init__() got an unexpected keyword argument 'objectId'
dankrause commented 9 years ago

It looks like you may have altered Client.__init__ in such a way that it no longer works. Can we see your class definition? You most likely just have to accept **kwargs and pass it through to Object.__init__ to fix the issue.

hugoliv commented 9 years ago

Ha ha, here is my class:

class Client(Object):
    pass
def __init__(self, name):
    self.name = name
dankrause commented 9 years ago

yep, that'll do it. You're not calling Object's constructor with the kwargs. Try this:

class Client(Object):
    def __init__(self, **kwargs):
        if 'name' not in kwargs:
            raise TypeError('Name is required')
        super(Client, self).__init__(**kwargs)

Then create them with Client(name="myname"). Of course, if name is not actually required, just leave out __init__ completely.

hugoliv commented 9 years ago

Ha ! That does the trick ! Thank you !