henry3260 commented on code in PR #59508:
URL: https://github.com/apache/airflow/pull/59508#discussion_r2627987716


##########
airflow-core/tests/unit/dag_processing/bundles/test_dag_bundle_manager.py:
##########
@@ -250,7 +253,7 @@ def test_sync_bundles_to_db_with_template(clear_db, 
session):
         manager.sync_bundles_to_db()
 
     # Check that the template and parameters were stored
-    bundle_model = 
session.query(DagBundleModel).filter_by(name="template-bundle").first()
+    bundle_model = 
session.scalars(select(DagBundleModel).filter_by(name="template-bundle").limit(1)).first()

Review Comment:
   > Since `.first()` already applies to the result, I believe we don’t need to 
add `.limit(1)` here.
   > 
   > What do you think ?
   
   Thanks — good point about simplifying the call. Just to explain: .first() is 
a client-side operation on the SQLAlchemy result and does not add a SQL LIMIT. 
Without a SQL-level LIMIT, the database may return multiple rows which are then 
transmitted to the client and discarded when .first() is applied — this can 
cause unnecessary I/O and CPU work, especially if the query could match many 
rows. To make the intent and performance characteristics explicit, I prefer 
keeping the SQL-level limit.



-- 
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