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

Signature of create_superuser() not allways compatible with Django's own #111

Open
tiktuk opened this issue Apr 2, 2020 · 1 comment
Open

Comments

@tiktuk
Copy link

tiktuk commented Apr 2, 2020

I am trying to write a pytest test of one of my views that requires a logged-in admin user and I'm using the pytest-django admin_client fixture for that.

This fails as follows:

        try:
            user = UserModel._default_manager.get(**{username_field: username})
        except UserModel.DoesNotExist:
            extra_fields = {}
            if username_field not in ("username", "email"):
                extra_fields[username_field] = "admin"
            user = UserModel._default_manager.create_superuser(
>               username, "admin@example.com", "password", **extra_fields
            )
E           TypeError: create_superuser() takes 1 positional argument but 4 were given

../.virtualenvs/test3/lib/python3.7/site-packages/pytest_django/fixtures.py:298: TypeError

I investigated and it's because authtools defines create_superuser like this:

    def create_superuser(self, **kwargs):

using only one positional argument (self). The pytest-django fixture tries to invoke the function like Django expects up until 3.0, using username, email and password. In 3.0 only username is required so this problem might be solved but I'm on 2.2 and you seem to support 1.11 and maybe earlier too.

So is this a bug? I can work around it for now but thought I'd notify you. And thanks for a great package btw ☺️ .

@bgaudino
Copy link
Contributor

Thanks for the issue and sorry for letting this sit for so long. We're unsure how to update this without breaking backwards compatibility, but we are open to ideas and PRs.

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

No branches or pull requests

2 participants