-
Notifications
You must be signed in to change notification settings - Fork 5
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
Ensure that user_name
values for all User
are lowercase and do not contain whitespace
#597
Conversation
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.
Looks good. Only minor potential patch, but not blocking.
for user in session.execute(sa.select(users)): | ||
session.execute(users.update().where(users.c.id == user.id).values(user_name=user.user_name.lower())) |
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.
I think this could be done with a single query:
session.execute(users.update().values({users.c.id: func.lower(users.c.id)})
Oh, I only noticed this PR now. Great ! More harmonization with JupyterHub Question about the DB migration, if it encounters existing username with uppercase and try to convert to a lowercase version, will it display which users were converted so the node admin can notify the users impacted they have to now use lowercase to login? What if the conversion clashes with existing lowercase version? |
It won't display it (in the current state).
The migration will purposely crash. Magpie will not be able to boot, and therefore the rest of the stack also. |
I assume when Magpie crashes, it will display/log the conflicting existing username causing the crash and the matching uppercase version? |
Magpie will report the error to boot after the configured number of DB connect/migration retries (default 5). |
Since the case insensitive unique index is created first (before existing usernames are converted to lowercase). Alembic will report an error indicating which values are in conflict before any conversion happens. This will give the user a good idea of which names are in conflict and they can update the values manually. I've added a comment in the migration script as well with this information and added additional information to the error message. |
@mishaschwartz Thanks for logging the error when migration fails.
When migration succeeds, please also log which users were migrated so the node admin can notify those users to use lowercase instead of uppercase. |
Ok sounds good. Done now |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #597 +/- ##
=======================================
Coverage 80.92% 80.92%
=======================================
Files 73 73
Lines 10194 10196 +2
Branches 1824 1824
=======================================
+ Hits 8249 8251 +2
Misses 1622 1622
Partials 323 323 ☔ View full report in Codecov by Sentry. |
Ziggurat foundations assumes that a
User
will not have auser_name
that differs from another only in terms of case. The simplest way to enforce this is to ensure that alluser_name
values are lowercase.Previously, this was not enforced so we could create two
User
which could not be differentiated properly.This change includes a database migration that will convert all
user_name
that contain uppercase characters to lowercase. This may cause a database conflict if there are twouser_name
values that differ only in terms of case. For example "Test" and "test". If this occurs, please manually update thoseuser_name
values to no longer conflict and try the migration again.This also prevents new users from being created that contain whitespace.
Replaces #596
Resolves #595