uranusjr commented on code in PR #32177:
URL: https://github.com/apache/airflow/pull/32177#discussion_r1243427594


##########
airflow/utils/db.py:
##########
@@ -92,7 +92,7 @@ def _format_airflow_moved_table_name(source_table, version, 
category):
 @provide_session
 def merge_conn(conn, session: Session = NEW_SESSION):
     """Add new Connection."""
-    if not 
session.query(conn.__class__).filter_by(conn_id=conn.conn_id).first():
+    if not 
session.scalar(select(conn.__class__).filter_by(conn_id=conn.conn_id).limit(1)):

Review Comment:
   Not strictly related but we should refactor this to use `count()` or `SELECT 
TRUE` to avoid populating the Python object unnecessarily.



##########
airflow/utils/db.py:
##########
@@ -959,7 +959,9 @@ def check_conn_id_duplicates(session: Session) -> 
Iterable[str]:
 
     dups = []
     try:
-        dups = 
session.query(Connection.conn_id).group_by(Connection.conn_id).having(func.count()
 > 1).all()
+        dups = session.execute(
+            
select(Connection.conn_id).group_by(Connection.conn_id).having(func.count() > 1)
+        ).all()

Review Comment:
   Probably this as well; a bit more difficult to rewrite, but simply changing 
this to `first()` would help.



##########
airflow/utils/db.py:
##########
@@ -984,12 +986,11 @@ def check_username_duplicates(session: Session) -> 
Iterable[str]:
     for model in [User, RegisterUser]:
         dups = []
         try:
-            dups = (
-                session.query(model.username)  # type: ignore[attr-defined]
+            dups = session.execute(
+                select(model.username)  # type: ignore[attr-defined]
                 .group_by(model.username)  # type: ignore[attr-defined]
                 .having(func.count() > 1)
-                .all()
-            )
+            ).all()

Review Comment:
   Same as above.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to