-
Notifications
You must be signed in to change notification settings - Fork 9
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
Feat: check for existing superuser #1851
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
@@ -23,7 +23,7 @@ python manage.py migrate | |||
# check DJANGO_ADMIN = true, default to false if empty or unset | |||
|
|||
if [[ ${DJANGO_ADMIN:-false} = true ]]; then | |||
python manage.py createsuperuser --no-input | |||
cat benefits/superuser.py | python manage.py shell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much more elegant than the pure shell
approach 👍
Since we are introducing new Python code though, I'd like to see some test coverage, e.g. for each of the conditionals.
|
||
User = get_user_model() # get the currently active user model | ||
|
||
username = os.environ.get("DJANGO_SUPERUSER_USERNAME") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the env vars are undefined, os.environ.get(....)
hides this fact and the code continues along, only blowing up later.
I think we can use os.environ[...]
here since these are all required values.
raise RuntimeError("A user already exists with DJANGO_SUPERUSER_NAME as the username") | ||
else: | ||
email = os.environ.get("DJANGO_SUPERUSER_EMAIL") | ||
password = os.environ.get("DJANGO_SUPERUSER_PASSWORD") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about os.environ[...]
for these two.
Closing in favor of #1856 |
If
./bin/init.sh
has already been run and then is run again withDB_RESET
set tofalse
, it runs into an error related to the superuser:Log snippet
This PR checks if the superuser already exists and if not, creates it using
User.create_superuser
.