Skip to content

Conversation

bluetech
Copy link
Member

Replaces PR #843 with some minor updates. Commits by @jnns.


Using the admin_client fixture with a custom user model that doesn't have a username field doesn't work currently. The fixture assumes that the user model always has a username field present. For this case, Django has User.USERNAME_FIELD and User.get_username().

Unfortunately, the existing test didn't catch this issue because a custom user model with User.username is used.

This pull request changes the test setup to use a custom user without username and makes admin_client use User.get_username().

There are a few merge requests and issues about this problem already. I hope this one meets the requirements to be merged. If not, please let me know and I see what I can do.

Closes #246
Closes #484
Closes #748
Fixes #457

jnns and others added 3 commits October 16, 2020 15:37
The previous test setup inherited from AbstractUser thus MyCustomUser
still had a username field.

The problems people are having when using the admin_client fixture in
combination with a custom user model are due to the username field
not being present.

This change accounts for the more realistic scenario.
Relying on `User.USERNAME_FIELD` is enough for light customization and
doesn't require `extra_arguments`.

Esoteric user models probably need a specially tailored manager anyway
and most likely a custom `django_user` fixture that goes with that.
@bluetech bluetech force-pushed the jnns-admin-client-fix branch from 7a8716f to c7f27cb Compare October 16, 2020 12:39
@bluetech
Copy link
Member Author

It turns out mysql has some restriction on the max_size of unique indexes, so I lowered the EmailField max_size from 254 to 100.

@bluetech bluetech merged commit 18b5776 into pytest-dev:master Oct 16, 2020
@bluetech bluetech deleted the jnns-admin-client-fix branch October 27, 2023 11:41
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.

If user model changes the username field, admin_user fixture will pass it twice
2 participants