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

setter for user DUMMY_FIELDS not available for django get_or_create() #12700

Open
2 tasks done
JanMalte opened this issue Oct 7, 2024 · 4 comments
Open
2 tasks done
Labels
enhancement Adding or requesting a new feature. good first issue Opportunity for newcoming contributors. hacktoberfest This is suitable for Hacktoberfest. Don’t try to spam. help wanted Extra attention is needed.

Comments

@JanMalte
Copy link

JanMalte commented Oct 7, 2024

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

  • 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.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

@nijel
Copy link
Member

nijel commented Oct 8, 2024

This is currently supported only for LDAP which passes attributes via extra_data. Adding support for other authentication backends is certainly possible.

@nijel nijel added enhancement Adding or requesting a new feature. hacktoberfest This is suitable for Hacktoberfest. Don’t try to spam. help wanted Extra attention is needed. good first issue Opportunity for newcoming contributors. labels Oct 8, 2024
Copy link

github-actions bot commented Oct 8, 2024

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.

@JezFirth
Copy link
Contributor

Currently having a look at this

@Fjtg
Copy link
Contributor

Fjtg commented Oct 24, 2024

having a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adding or requesting a new feature. good first issue Opportunity for newcoming contributors. hacktoberfest This is suitable for Hacktoberfest. Don’t try to spam. help wanted Extra attention is needed.
Projects
None yet
Development

No branches or pull requests

4 participants