WeblateOrg/weblate

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

JanMalte opened this issue · 2 comments

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

  • I've read and searched the documentation.
  • I've searched for similar filed issues in this repository.

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: 5.4.3
  • Django: 4.2.16

Weblate deploy checks

No response

Additional context

No response

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.

This issue has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!