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

Fixed issue in create_user #370

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

crazyscientist
Copy link

The function assumed that User.get_by_type_and_id returns a User instance or None. However, this called method raises a helios_auth.models.User.DoesNotExist exception.

This commit changes the behavior of create_user to match the behavior of User.get_by_type_and_id.

The function assumed that `User.get_by_type_and_id` returns a User instance or None. However, this
called method raises a `helios_auth.models.User.DoesNotExist` exception.

This commit changes the behavior of `create_user` to match the behavior of `User.get_by_type_and_id`.
@crazyscientist
Copy link
Author

Example

$ ./manage.py shell
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import django
>>> from helios_auth.models import User
>>> from helios_auth.auth_systems.password import create_user
>>> django.VERSION
(2, 2, 24, 'final', 0)
>>> create_user("andi","very-secret-password", "Andi")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/andi/workspace/helios-server/helios_auth/auth_systems/password.py", line 24, in create_user
    user = User.get_by_type_and_id('password', username)
  File "/home/andi/workspace/helios-server/helios_auth/models.py", line 48, in get_by_type_and_id
    return cls.objects.get(user_type = user_type, user_id = user_id)
  File "/home/andi/virtualenvs/helios/lib/python3.10/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/andi/virtualenvs/helios/lib/python3.10/site-packages/django/db/models/query.py", line 406, in get
    raise self.model.DoesNotExist(
helios_auth.models.User.DoesNotExist: User matching query does not exist.

Note: I only tested this with Python 3.10 and Django 2.21

Footnotes

  1. I'm fairly sure, that more recent Django versions behave identically.

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

Successfully merging this pull request may close these issues.

None yet

1 participant