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

Fix ./manage.py createsuperuser #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pconerly
Copy link
Collaborator

@pconerly pconerly commented Jun 1, 2022

When I run ./manage.py createsuperuser I get an error:

(eth3) [peterconerly@secretproject]$ ./manage.py createsuperuser
Ethereum address: 0xmyethaddr
Password: 
Password (again): 
Traceback (most recent call last):
  File "/Users/peterconerly/code/secretproject/./manage.py", line 22, in <module>
    main()
  File "/Users/peterconerly/code/secretproject/./manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/peterconerly/.virtualenvs/eth3/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/Users/peterconerly/.virtualenvs/eth3/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/peterconerly/.virtualenvs/eth3/lib/python3.10/site-packages/django/core/management/base.py", line 414, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/peterconerly/.virtualenvs/eth3/lib/python3.10/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 87, in execute
    return super().execute(*args, **options)
  File "/Users/peterconerly/.virtualenvs/eth3/lib/python3.10/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "/Users/peterconerly/.virtualenvs/eth3/lib/python3.10/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 232, in handle
    self.UserModel._default_manager.db_manager(database).create_superuser(
TypeError: WalletManager.create_superuser() got an unexpected keyword argument 'password'

I was able to fix it by adding password as an (ignored) parameter to WalletManager.create_superuser but this feels like a pretty inelegant solution.

I'm also not clear how the command createsuperuser is modified from Django. (And how did Django know to ask for the Ethereum address field?)

Creating a superuser also didn't trigger data fetch from an ethereum data provider, but that's probably fine. :D

Is there a better way to fix this bug? (And is this hacky solution going to fail some future mypy type-checking or linting?)

@@ -40,7 +40,7 @@ def _nonce_is_valid(nonce: str) -> bool:

class SiweBackend(BaseBackend):
"""
Authenticate an Ethereum address as per Sing-In with Ethereum (EIP-4361).
Authenticate an Ethereum address as per Sign-In with Ethereum (EIP-4361).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

@payton
Copy link
Owner

payton commented Jun 2, 2022

And how did Django know to ask for the Ethereum address field?

This is because of https://github.com/payton/django-siwe-auth/blob/main/README.md?plain=1#L174

Creating a superuser also didn't trigger data fetch from an ethereum data provider, but that's probably fine. :D

Agreed! I don't think creating a superuser should trigger any authentication workflows. Ideally I can just pass in an ethereum address for createsuperuser.

Is there a better way to fix this bug?

As far as creating a superuser goes, I think we may need a deeper override if possible. If that's not possible, it may be better to just instruct users to add a user to the DB directly and toggle the superuser column.

There's also another issue with admin logins. We want to be able to use SIWE while signing in to the Django admin panel. That's covered in this issue #7

@payton
Copy link
Owner

payton commented Jun 2, 2022

I was able to fix it by adding password as an (ignored) parameter to WalletManager.create_superuser but this feels like a pretty inelegant solution.

I'm going to hold off on landing this one temporarily since we maybe able to find a more concrete alternative!

@pconerly
Copy link
Collaborator Author

pconerly commented Jun 3, 2022

I'm going to hold off on landing this one temporarily since we maybe able to find a more concrete alternative!

Totally reasonable 👍

@pconerly
Copy link
Collaborator Author

pconerly commented Jun 9, 2022

Okay, yeah, this is totally a bad solution. I was using Wallet.objects.create_superuser and it would've been annoying to have to add a password field.

I've discovered that you can override django management commands by have a command of the same name. I have WIP branch here:
https://github.com/NorthwestNFTs/django-siwe-auth/tree/createsuperuser_override

The main issue is that siwe_auth/createsuperuser assumes that AUTH_USER_MODEL = "siwe_auth.Wallet". If AUTH_USER_MODEL isn't set to that, it should defer to the next createsuperuser command, which needs some investigation.

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.

2 participants