milesrichardson / ParsePy

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

Attempt to set ACL returns "object has no attribute 'ACL'" #97

Closed flound1129 closed 9 years ago

flound1129 commented 9 years ago
    answer.User = user
    answer.ACL.set_user(user, read=True, write=True)
    answer.ACL.set_default(read=True)
    answer.ACL.set_role('admin', read=True, write=True)
    answer.save();

returns:

Traceback (most recent call last): File "./fix_Question.py", line 32, in answer.ACL.set_user(user, read=True, write=True) File "/usr/local/lib/python2.7/dist-packages/parse_rest-0.2.20141004-py2.7.egg/parse_rest/datatypes.py", line 326, in getattr return object.getattribute(self, attr) #preserve default if attr not exists AttributeError: 'Question' object has no attribute 'ACL'

mcastle commented 9 years ago

The code you posted does not have any Question object. Can you post the code that has the Question object.

flound1129 commented 9 years ago

class Question(Object): pass

dgrtwo commented 9 years ago

That doesn't help. When is answer defined, and when is user defined? Is one of them a Question object?

flound1129 commented 9 years ago

yes, answer is a question object.

answers = Question.Query.filter(parent__exists=False).filter(autoquestionid__exists=True).limit(1000).skip(skip)

if len(answers) > 1000:
    done = True
else:
    skip += 1000

for answer in answers:
    print "id was %s" % answer.objectId
    asker = answer.askedof
    user = User()
    user.objectId = asker
    answer.parent = answer.autoquestionid
    answer.User = user
flound1129 commented 9 years ago

It seems to work if the answer object already has an ACL set. However if there is not currently an ACL set, it throws the exception.

flound1129 commented 9 years ago

Also, if I try to initialiaze an ACL object like so:

class acl(ACL): pass

answer.ACL = acl()

I get this exception.

Traceback (most recent call last): File "./fix_Question.py", line 32, in answer.ACL = acl() TypeError: init() takes exactly 2 arguments (1 given)

It's not clear what it's expecting to get as an argument.

flound1129 commented 9 years ago

Hi were you able to reproduce this issue? Or am I doing something stupid?

mcastle commented 9 years ago

This is indeed a bug that happens when first trying to set the ACL for an object. I've gotten around this using, as written for your example:

answer.ACL = ACL({user.objectId: {'read': True, 'write': True}})

Subsequently, the ACL can be set and retrieved using the method described in the docs.

flound1129 commented 9 years ago

Workaround seems to work. Thanks!