kaxil commented on code in PR #44843:
URL: https://github.com/apache/airflow/pull/44843#discussion_r1884264997


##########
tests/models/test_renderedtifields.py:
##########
@@ -158,16 +163,35 @@ def test_get_templated_fields(self, templated_field, 
expected_rendered_field, da
         assert ti.dag_id == rtif.dag_id
         assert ti.task_id == rtif.task_id
         assert ti.run_id == rtif.run_id
-        assert expected_rendered_field == 
rtif.rendered_fields.get("bash_command")
+        if type(templated_field) is set:
+            # the output order of a set is non-deterministic and can change 
per process.
+            # this validation can fail if that happens before stringification, 
so we convert to set and compare.
+            assert ast.literal_eval(expected_rendered_field) == 
ast.literal_eval(
+                rtif.rendered_fields.get("bash_command")
+            )
+        else:
+            assert expected_rendered_field == 
rtif.rendered_fields.get("bash_command")
 
         session.add(rtif)
         session.flush()
 
-        assert RTIF.get_templated_fields(ti=ti, session=session) == {
-            "bash_command": expected_rendered_field,
-            "env": None,
-            "cwd": None,
-        }
+        if type(templated_field) is set:

Review Comment:
   This is in tests we control the parameters so not a big deal here anyway and 
more a "nit" -- but to illustrate the reason:
   
   ```py
   In [13]: class CustomSet(set):
       ...:     def add(self, element):
       ...:         print(f"Adding element: {element}")
       ...:         super().add(element)
       ...:
   
   In [15]: a = CustomSet([1,2])
   
   In [16]: isinstance(a, set)
   Out[16]: True
   
   In [17]: type(a) is set
   Out[17]: False
   ```



##########
tests/models/test_renderedtifields.py:
##########
@@ -158,16 +163,35 @@ def test_get_templated_fields(self, templated_field, 
expected_rendered_field, da
         assert ti.dag_id == rtif.dag_id
         assert ti.task_id == rtif.task_id
         assert ti.run_id == rtif.run_id
-        assert expected_rendered_field == 
rtif.rendered_fields.get("bash_command")
+        if type(templated_field) is set:
+            # the output order of a set is non-deterministic and can change 
per process.
+            # this validation can fail if that happens before stringification, 
so we convert to set and compare.
+            assert ast.literal_eval(expected_rendered_field) == 
ast.literal_eval(
+                rtif.rendered_fields.get("bash_command")
+            )
+        else:
+            assert expected_rendered_field == 
rtif.rendered_fields.get("bash_command")
 
         session.add(rtif)
         session.flush()
 
-        assert RTIF.get_templated_fields(ti=ti, session=session) == {
-            "bash_command": expected_rendered_field,
-            "env": None,
-            "cwd": None,
-        }
+        if type(templated_field) is set:

Review Comment:
   This is in tests so we control the parameters so not a big deal here anyway 
and more a "nit" -- but to illustrate the reason:
   
   ```py
   In [13]: class CustomSet(set):
       ...:     def add(self, element):
       ...:         print(f"Adding element: {element}")
       ...:         super().add(element)
       ...:
   
   In [15]: a = CustomSet([1,2])
   
   In [16]: isinstance(a, set)
   Out[16]: True
   
   In [17]: type(a) is set
   Out[17]: False
   ```



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