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 2021/03/20 01:42:54 UTC

[GitHub] [airflow] kaxil opened a new pull request #14909: Sort lists, sets and tuples in Serialized DAGs

kaxil opened a new pull request #14909:
URL: https://github.com/apache/airflow/pull/14909


   Currently, we check if the dag changed or not via dag_hash.
   The problem is since the insertion order is not guaranteed, it produces
   a different hash and hence results in a DB write unnecessarily.
   
   Example:
   
   ![image](https://user-images.githubusercontent.com/8811558/111855581-89917400-891d-11eb-8225-7f81ab740e8b.png)
   
   
   This commit fixes it.
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   


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

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



[GitHub] [airflow] github-actions[bot] commented on pull request #14909: Sort lists, sets and tuples in Serialized DAGs

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14909:
URL: https://github.com/apache/airflow/pull/14909#issuecomment-803225408


   The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest master at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.


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

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



[GitHub] [airflow] ernest-kr commented on pull request #14909: Sort lists, sets and tuples in Serialized DAGs

Posted by GitBox <gi...@apache.org>.
ernest-kr commented on pull request #14909:
URL: https://github.com/apache/airflow/pull/14909#issuecomment-816328584


   I verified this fix in 2.0.2 dev. 
   
   ```json
   {
      "__version":1,
      "dag":{
         "max_active_runs":3,
         "_dag_id":"example_dag_25000_1",
         "timezone":"UTC",
         "fileloc":"/usr/local/airflow/dags/dags_25000/example_dag_25000.py",
         "_task_group":{
            "_group_id":null,
            "prefix_group_id":true,
            "tooltip":"",
            "ui_color":"CornflowerBlue",
            "ui_fgcolor":"#000",
            "children":{
               "tasks__1_of_10":[
                  "operator",
                  "tasks__1_of_10"
               ],
               "tasks__2_of_10":[
                  "operator",
                  "tasks__2_of_10"
               ],
               "tasks__3_of_10":[
                  "operator",
                  "tasks__3_of_10"
               ],
               "tasks__4_of_10":[
                  "operator",
                  "tasks__4_of_10"
               ],
               "tasks__5_of_10":[
                  "operator",
                  "tasks__5_of_10"
               ],
               "tasks__6_of_10":[
                  "operator",
                  "tasks__6_of_10"
               ],
               "tasks__7_of_10":[
                  "operator",
                  "tasks__7_of_10"
               ],
               "tasks__8_of_10":[
                  "operator",
                  "tasks__8_of_10"
               ],
               "tasks__9_of_10":[
                  "operator",
                  "tasks__9_of_10"
               ],
               "tasks__10_of_10":[
                  "operator",
                  "tasks__10_of_10"
               ]
            },
            "upstream_group_ids":[
               
            ],
            "downstream_group_ids":[
               
            ],
            "upstream_task_ids":[
               
            ],
            "downstream_task_ids":[
               
            ]
         },
         "schedule_interval":"@hourly",
         "start_date":1617840000.0,
         "tasks":[
            {
               "ui_color":"#f0ede4",
               "ui_fgcolor":"#000",
               "label":"tasks__1_of_10",
               "_inlets":[
                  
               ],
               "_downstream_task_ids":[
                  "tasks__2_of_10",
                  "tasks__3_of_10"
               ],
               "template_fields":[
                  "bash_command",
                  "env"
               ],
               "pool":"default_pool",
               "template_fields_renderers":{
                  "bash_command":"bash",
                  "env":"json"
               },
               "task_id":"tasks__1_of_10",
               "_outlets":[
                  
               ],
               "_task_type":"BashOperator",
               "_task_module":"airflow.operators.bash",
               "_is_dummy":false,
               "bash_command":"echo 0408_2"
            },
            {
               "ui_color":"#f0ede4",
               "ui_fgcolor":"#000",
               "label":"tasks__2_of_10",
               "_inlets":[
                  
               ],
               "_downstream_task_ids":[
                  "tasks__4_of_10",
                  "tasks__5_of_10"
               ],
               "template_fields":[
                  "bash_command",
                  "env"
               ],
               "pool":"default_pool",
               "template_fields_renderers":{
                  "bash_command":"bash",
                  "env":"json"
               },
               "task_id":"tasks__2_of_10",
               "_outlets":[
                  
               ],
               "_task_type":"BashOperator",
               "_task_module":"airflow.operators.bash",
               "_is_dummy":false,
               "bash_command":"echo 0408_2"
            },
            {
               "ui_color":"#f0ede4",
               "ui_fgcolor":"#000",
               "label":"tasks__3_of_10",
               "_inlets":[
                  
               ],
               "_downstream_task_ids":[
                  "tasks__6_of_10",
                  "tasks__7_of_10"
               ],
               "template_fields":[
                  "bash_command",
                  "env"
               ],
               "pool":"default_pool",
               "template_fields_renderers":{
                  "bash_command":"bash",
                  "env":"json"
               },
               "task_id":"tasks__3_of_10",
               "_outlets":[
                  
               ],
               "_task_type":"BashOperator",
               "_task_module":"airflow.operators.bash",
               "_is_dummy":false,
               "bash_command":"echo 0408_2"
            },
            {
               "ui_color":"#f0ede4",
               "ui_fgcolor":"#000",
               "label":"tasks__4_of_10",
               "_inlets":[
                  
               ],
               "_downstream_task_ids":[
                  "tasks__8_of_10",
                  "tasks__9_of_10"
               ],
               "template_fields":[
                  "bash_command",
                  "env"
               ],
               "pool":"default_pool",
               "template_fields_renderers":{
                  "bash_command":"bash",
                  "env":"json"
               },
               "task_id":"tasks__4_of_10",
               "_outlets":[
                  
               ],
               "_task_type":"BashOperator",
               "_task_module":"airflow.operators.bash",
               "_is_dummy":false,
               "bash_command":"echo 0408_2"
            },
            {
               "ui_color":"#f0ede4",
               "ui_fgcolor":"#000",
               "label":"tasks__5_of_10",
               "_inlets":[
                  
               ],
               "_downstream_task_ids":[
                  "tasks__10_of_10"
               ],
               "template_fields":[
                  "bash_command",
                  "env"
               ],
               "pool":"default_pool",
               "template_fields_renderers":{
                  "bash_command":"bash",
                  "env":"json"
               },
               "task_id":"tasks__5_of_10",
               "_outlets":[
                  
               ],
               "_task_type":"BashOperator",
               "_task_module":"airflow.operators.bash",
               "_is_dummy":false,
               "bash_command":"echo 0408_2"
            },
            {
               "ui_color":"#f0ede4",
               "ui_fgcolor":"#000",
               "label":"tasks__6_of_10",
               "_inlets":[
                  
               ],
               "_downstream_task_ids":[
                  
               ],
               "template_fields":[
                  "bash_command",
                  "env"
               ],
               "pool":"default_pool",
               "template_fields_renderers":{
                  "bash_command":"bash",
                  "env":"json"
               },
               "task_id":"tasks__6_of_10",
               "_outlets":[
                  
               ],
               "_task_type":"BashOperator",
               "_task_module":"airflow.operators.bash",
               "_is_dummy":false,
               "bash_command":"echo 0408_2"
            },
            {
               "ui_color":"#f0ede4",
               "ui_fgcolor":"#000",
               "label":"tasks__7_of_10",
               "_inlets":[
                  
               ],
               "_downstream_task_ids":[
                  
               ],
               "template_fields":[
                  "bash_command",
                  "env"
               ],
               "pool":"default_pool",
               "template_fields_renderers":{
                  "bash_command":"bash",
                  "env":"json"
               },
               "task_id":"tasks__7_of_10",
               "_outlets":[
                  
               ],
               "_task_type":"BashOperator",
               "_task_module":"airflow.operators.bash",
               "_is_dummy":false,
               "bash_command":"echo 0408_2"
            },
            {
               "ui_color":"#f0ede4",
               "ui_fgcolor":"#000",
               "label":"tasks__8_of_10",
               "_inlets":[
                  
               ],
               "_downstream_task_ids":[
                  
               ],
               "template_fields":[
                  "bash_command",
                  "env"
               ],
               "pool":"default_pool",
               "template_fields_renderers":{
                  "bash_command":"bash",
                  "env":"json"
               },
               "task_id":"tasks__8_of_10",
               "_outlets":[
                  
               ],
               "_task_type":"BashOperator",
               "_task_module":"airflow.operators.bash",
               "_is_dummy":false,
               "bash_command":"echo 0408_2"
            },
            {
               "ui_color":"#f0ede4",
               "ui_fgcolor":"#000",
               "label":"tasks__9_of_10",
               "_inlets":[
                  
               ],
               "_downstream_task_ids":[
                  
               ],
               "template_fields":[
                  "bash_command",
                  "env"
               ],
               "pool":"default_pool",
               "template_fields_renderers":{
                  "bash_command":"bash",
                  "env":"json"
               },
               "task_id":"tasks__9_of_10",
               "_outlets":[
                  
               ],
               "_task_type":"BashOperator",
               "_task_module":"airflow.operators.bash",
               "_is_dummy":false,
               "bash_command":"echo 0408_2"
            },
            {
               "ui_color":"#f0ede4",
               "ui_fgcolor":"#000",
               "label":"tasks__10_of_10",
               "_inlets":[
                  
               ],
               "_downstream_task_ids":[
                  
               ],
               "template_fields":[
                  "bash_command",
                  "env"
               ],
               "pool":"default_pool",
               "template_fields_renderers":{
                  "bash_command":"bash",
                  "env":"json"
               },
               "task_id":"tasks__10_of_10",
               "_outlets":[
                  
               ],
               "_task_type":"BashOperator",
               "_task_module":"airflow.operators.bash",
               "_is_dummy":false,
               "bash_command":"echo 0408_2"
            }
         ]
      }
   }
   ```


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

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



[GitHub] [airflow] kaxil commented on a change in pull request #14909: Sort lists, sets and tuples in Serialized DAGs

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #14909:
URL: https://github.com/apache/airflow/pull/14909#discussion_r598044524



##########
File path: tests/serialization/test_dag_serialization.py
##########
@@ -1027,6 +1027,33 @@ def test_dag_on_failure_callback_roundtrip(self, passed_failure_callback, expect
 
         assert deserialized_dag.has_on_failure_callback is expected_value
 
+    @parameterized.expand(
+        [
+            (
+                ['task_1', 'task_5', 'task_2', 'task_4'],
+                ['task_1', 'task_2', 'task_4', 'task_5'],
+            ),
+            (
+                {'task_1', 'task_5', 'task_2', 'task_4'},
+                ['task_1', 'task_2', 'task_4', 'task_5'],
+            ),
+            (
+                ('task_1', 'task_5', 'task_2', 'task_4'),
+                ['task_1', 'task_2', 'task_4', 'task_5'],
+            ),
+            (
+                {"task3": "test3", "task2": "test2", "task1": "test1"},
+                {"task1": "test1", "task2": "test2", "task3": "test3"},
+            ),
+        ]
+    )
+    def test_serialized_objects_are_sorted(self, object_to_serialized, expected_output):
+        """Test Serialized Lists, Sets and Tuples are sorted"""
+        serialized_obj = SerializedDAG._serialize(object_to_serialized)
+        if isinstance(serialized_obj, dict) and "__type" in serialized_obj:
+            serialized_obj = serialized_obj["__var"]

Review comment:
       This is to take care of the following code:
   
   https://github.com/apache/airflow/blob/2f32df7b711cf63d18efd5e0023b22a79040cc86/airflow/serialization/serialized_objects.py#L190-L193




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

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



[GitHub] [airflow] kaxil merged pull request #14909: Sort lists, sets and tuples in Serialized DAGs

Posted by GitBox <gi...@apache.org>.
kaxil merged pull request #14909:
URL: https://github.com/apache/airflow/pull/14909


   


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

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