You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/10/26 09:51:00 UTC

[GitHub] [airflow] ashb commented on a diff in pull request #27266: Add case insensitive constraint to username

ashb commented on code in PR #27266:
URL: https://github.com/apache/airflow/pull/27266#discussion_r1005465343


##########
airflow/utils/db.py:
##########
@@ -930,6 +930,36 @@ def check_conn_id_duplicates(session: Session) -> Iterable[str]:
         )
 
 
+def check_username_duplicates(session: Session) -> Iterable[str]:
+    """
+    Check unique username in User & RegisterUser table
+
+    :param session:  session of the sqlalchemy
+    :rtype: str
+    """
+    from airflow.www.fab_security.sqla.models import RegisterUser, User
+
+    for model in [User, RegisterUser]:
+        dups = []
+        try:
+            dups = (
+                session.query(model.username)  # type: ignore[attr-defined]
+                .group_by(model.username)  # type: ignore[attr-defined]
+                .having(func.count() > 1)
+                .all()
+            )
+        except (exc.OperationalError, exc.ProgrammingError):
+            # fallback if tables hasn't been created yet
+            session.rollback()
+        if dups:
+            yield (
+                f'Seems you have non unique username in {model.__table__.name} table.\n'  # type: ignore
+                'You have to manage those duplicate usernames '

Review Comment:
   This needs to say something about mixed-case, as otherwise users could be forgiven for thinking that `Test` and `test` are different users.
   
   And "manage" isn't clear either -> "delete or rename"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org