question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError exception when accessing current user using Parse Server

See original GitHub issue

EDIT FOR FUTURE: see https://github.com/milesrichardson/ParsePy/issues/155#issuecomment-271482650 for solution

Using Parse Server, I am encountering a crash at line 442 in datatypes.py setattr(self, key, ParseType.convert_from_parse(key, value)) when retrieving the currently logged in user. The user object appears to be being loaded correctly, looking at both the server logs and the error page from my (Django) app.

This only happens using the self-hosted server, not the Parse service.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
francisjerviscommented, Jan 10, 2017

Confirming this is working on my end, thanks for such a quick fix!

1reaction
milesrichardsoncommented, Jan 10, 2017

@francisjervis This should be fixed now. You can install from master like pip install git+https://github.com/milesrichardson/ParsePy

Since I included a link to this issue in a comment at the location of the fix in the code, I’m putting the solution in this comment.

The problem was that setattr(self, key, ParseType.convert_from_parse(key, value)) was trying to set the attribute className on class ParseResource, but className conflicts with the existing ParseResource property:

    @property
    def className(self):
        return self.__class__.__name__

The offending code:

for key, value in six.iteritems(args):
    setattr(self, key, ParseType.convert_from_parse(key, value))

As far as I can see there were two solutions:

  1. Hard code an exception (no pun intended…) for the className attribute:
for key, value in six.iteritems(args):
    if key == 'className':
        continue
    setattr(self, key, ParseType.convert_from_parse(key, value))
  1. Skip any AttributeError
for key, value in six.iteritems(args):
    try:
        setattr(self, key, ParseType.convert_from_parse(key, value))
    except AttributeError:
        continue

I chose solution 2 because it’s more “future proof” in the case that there are any other attributes that conflict with existing properties of the ParseResource object.

As an aside, the reason this happened only with User objects is that User is derived from ParseResource, which has the conflicting className property, but all other objects are derived from Object, which does not have the conflicting className property.

Read more comments on GitHub >

github_iconTop Results From Across the Web

get method not working on Parse current User - Stack Overflow
I am making an express app with Parse. In my cloud code, I am trying to get an attribute of the current user,...
Read more >
Can't get the current user in cloud code - The Parse Community
Why I can't get the current user in my cloud code? Even though I pass a header X-Parse-Session-Token, user is still {} Cloud...
Read more >
Built-in Exceptions — Python 3.11.1 documentation
The built-in exception classes can be subclassed to define new exceptions; programmers are encouraged to derive new exceptions from the Exception class or...
Read more >
Exception and Error Handling in Python - DataCamp
Learn how to catch and handle exceptions in Python with our step-by-step ... An error can be a syntax (parsing) error, while there...
Read more >
Requests - Django REST framework
user or .auth properties. These errors originate from an authenticator as a standard AttributeError , however it's necessary that they be re-raised as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found