setter for user `DUMMY_FIELDS` not available for django `get_or_create()`
Describe the issue
The setter method used for the DUMMY_FIELDS for first_name and last_name in the weblate.auth.models.User is not working with the django internal get_or_create() defaults parameter.
A FieldError exception is raised if one of those fields is provides as defaults.
FieldError at /accounts/login/
Invalid field name(s) for model User: 'first_name', 'last_name'.
I already tried
- [X] I've read and searched the documentation.
- [X] 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.get_or_create(username='test', defaults={'first_name': 'Test'})
Expected behavior
A user is created and the full_name is set to Test
Screenshots
No response
Exception traceback
Traceback (most recent call last):
File "/Users/maltegerth/.local/share/poetry/virtualenvs/moll-translate-QA9TMEcw-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 916, in get_or_create
return self.get(**kwargs), False
^^^^^^^^^^^^^^^^^^
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.
During handling of the above exception, another exception occurred:
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 918, in get_or_create
params = self._extract_model_params(defaults, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/maltegerth/.local/share/poetry/virtualenvs/moll-translate-QA9TMEcw-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 999, in _extract_model_params
raise exceptions.FieldError(
django.core.exceptions.FieldError: Invalid field name(s) for model User: 'first_name'.
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 currently supported only for LDAP which passes attributes via extra_data. Adding support for other authentication backends is certainly possible.
This issue seems to be a good fit for newbie contributors. You are welcome to contribute to Weblate! Don't hesitate to ask any questions you would have while implementing this.
You can learn about how to get started in our contributors documentation.
Currently having a look at this
having a look
Thank you for your report; the issue you have reported has just been fixed.
- In case you see a problem with the fix, please comment on this issue.
- In case you see a similar problem, please open a separate issue.
- If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.