WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.56k stars 1.01k forks source link

Setting a primary key for new users is failing - weblate.auth.models.User.DoesNotExist #12707

Open JanMalte opened 1 week ago

JanMalte commented 1 week ago

Describe the issue

If you are using an authentication backend which is populating a value for the primary key weblate.auth.models.User.pk for new users, the check for creating the AuditLog is failing.

I already tried

Steps to reproduce the behavior

This can be reproduced in a simple django python shell (python src/manage.py shell):

from django.contrib.auth import get_user_model
User = get_user_model()
User.objects.create(pk=42, username='test')

Expected behavior

A new user is created and the id - primary key is set to 42

Screenshots

No response

Exception traceback

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/maltegerth/.local/share/poetry/virtualenvs/moll-translate-QA9TMEcw-py3.11/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maltegerth/.local/share/poetry/virtualenvs/moll-translate-QA9TMEcw-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 658, in create
    obj.save(force_insert=True, using=self.db)
  File "/Users/maltegerth/.local/share/poetry/virtualenvs/moll-translate-QA9TMEcw-py3.11/lib/python3.11/site-packages/weblate/auth/models.py", line 421, in save
    original = User.objects.get(pk=self.pk)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maltegerth/.local/share/poetry/virtualenvs/moll-translate-QA9TMEcw-py3.11/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maltegerth/.local/share/poetry/virtualenvs/moll-translate-QA9TMEcw-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 637, in get
    raise self.model.DoesNotExist(
weblate.auth.models.User.DoesNotExist: User matching query does not exist.

How do you run Weblate?

Other

Weblate versions

Weblate deploy checks

No response

Additional context

No response

nijel commented 1 week ago

This is never going to be supported. Weblate creates users internally as well (for bots or token access) and these will collide with externally managed primary key.