Successful login in shell, but Pycharm returns DoesNotExist

Pycharm is used for a Django project with GoogleAppEngine. The project file is properly configured, i.e. INSTALLED_APPS and AUTHENTICATION_BACKENDS properly defined. A class UserProfile(models.Model) is defined, and not sure this is relevant.

The authentication and login work correctly with: python runserver. Running this through Pycharm I get that the user model does not exist.

in auth/ it gets to the line:

user = UserModel._default_manager.get_by_natural_key(username) in the following snippet,

....user = UserModel._default_manager.get_by_natural_key(username)
....if user.check_password(password):
........return user
except UserModel.DoesNotExist:
....return None

and returns the exception UserModel.DoesNotExist.

When in the shell, however, this same line returns the appropriate user and the check_password returns true.

What is confusing is that it works in the shell, but not in the IDE. Are there any suggestions?
1 comment
Comment actions Permalink
You are more then likely using the wrong server in the run/debug configuration for your project.

If running a Django-Python application with Google App Engine a decision must made as how to integrate the GAE non-relational database into the project. Django is designed to operate with relational databases such as MySQL, and is not designed to work with non-relational databases,e.g. GAE and MongoDB.

There are several alternatives available for integrating the Django framework with GAE's non-relational database, and these will determine which server to choose in Pycharm's Run/Debug Configuration.

For example, if using django-dbindexer then run the project with the Django server, and not the GAE server. The application uses the "python runserver" command, and the middleware handles the queries to the database.

The reason the login failed is because, while using the GAE server, you are really outside of the django-dbindexer solution, and the database queries do not run properly.

Note that in debug as the code is stepped through the problem begins with the query to the database and not before. For example, the call to auth/ in authenticate returns the correct user model from the call get_user_model().

Please sign in to leave a comment.