LiamHecht commented on code in PR #75562:
URL: https://github.com/apache/airflow/pull/75562#discussion_r4502597255


##########
airflow-core/tests/unit/models/test_trigger.py:
##########
@@ -180,6 +180,96 @@ def test_clean_unused(session, dag_maker):
     assert {result.id for result in results} == {trigger1.id, trigger4.id, 
trigger5.id, trigger6.id}
 
 
+def _create_unused_trigger(session) -> int:
+    trigger = Trigger(classpath="airflow.triggers.testing.SuccessTrigger", 
kwargs={})
+    session.add(trigger)
+    session.commit()
+    return trigger.id
+
+
+def _clean_unused_adding_reference_before_delete(session, trigger_id, 
add_reference):
+    """Run clean_unused, executing ``add_reference`` right before its DELETE 
(#72061)."""
+    reference_added = False
+
+    def add_reference_before_delete(connection, cursor, statement, parameters, 
context, executemany):
+        nonlocal reference_added
+        normalized_statement = " ".join(statement.lower().replace('"', 
"").replace("`", "").split())
+        if not reference_added and "delete from trigger" in 
normalized_statement:
+            reference_added = True

Review Comment:
    Agreed, I removed the nonlocal. The hook no longer keeps any state: it adds 
the reference whenever it sees the DELETE FROM trigger statement, and each test 
then asserts the trigger survived, which also shows the reference was added.



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