You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "romsharon98 (via GitHub)" <gi...@apache.org> on 2024/01/19 15:32:50 UTC

[PR] Fix assignment of template field in `__init__` in `CloudDataTransferServiceCreateJobOperator` [airflow]

romsharon98 opened a new pull request, #36909:
URL: https://github.com/apache/airflow/pull/36909

   related: https://github.com/apache/airflow/issues/36484
   
   
   Fix:
   ```
   CloudDataTransferServiceCreateJobOperator's constructor lacks direct assignments for instance members corresponding to the following template fields (i.e., self.field_name = field_name or 
   super.__init__(field_name=field_name, ...) ):
   ['body']
   CloudDataTransferServiceCreateJobOperator's constructor contains invalid assignments to the following instance members that should be corresponding to template fields (i.e., self.field_name = 
   field_name):
   ['self.body']
   ```
   
   cc: @shahar1
   
   
   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   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 an 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/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+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 a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix assignment of template field in `__init__` in `CloudDataTransferServiceCreateJobOperator` [airflow]

Posted by "romsharon98 (via GitHub)" <gi...@apache.org>.
romsharon98 commented on code in PR #36909:
URL: https://github.com/apache/airflow/pull/36909#discussion_r1459606197


##########
airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py:
##########
@@ -236,7 +236,9 @@ def __init__(
         **kwargs,
     ) -> None:
         super().__init__(**kwargs)
-        self.body = deepcopy(body)
+        self.body = body
+        if isinstance(self.body, dict):
+            self.body = deepcopy(body)

Review Comment:
   As `body` is a templated field, it can also be of type string. While adding `string` to the typing is necessary, doing so may lead to a typing error. This is because it will treat `body` as a string, even though in the rest of the code, we use it as a dictionary.
   Maybe you have an idea to solve it? 😄 



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix assignment of template field in `__init__` in `CloudDataTransferServiceCreateJobOperator` [airflow]

Posted by "romsharon98 (via GitHub)" <gi...@apache.org>.
romsharon98 commented on code in PR #36909:
URL: https://github.com/apache/airflow/pull/36909#discussion_r1461458749


##########
tests/providers/google/cloud/operators/test_cloud_storage_transfer_service.py:
##########
@@ -324,21 +324,33 @@ def test_job_create_multiple(self, aws_hook, gcp_hook):
     # (could be anything else) just to test if the templating works for all
     # fields
     @pytest.mark.db_test
+    @pytest.mark.parametrize(
+        "body, excepted",
+        [
+            (
+                {"description": "{{ dag.dag_id }}"},
+                {
+                    "description": "TestGcpStorageTransferJobCreateOperator_test_templates",
+                },
+            ),
+            ("{{ dag.dag_id }}", "TestGcpStorageTransferJobCreateOperator_test_templates"),

Review Comment:
   it's not, but this test just checking the rendering.



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix assignment of template field in `__init__` in `CloudDataTransferServiceCreateJobOperator` [airflow]

Posted by "dirrao (via GitHub)" <gi...@apache.org>.
dirrao commented on code in PR #36909:
URL: https://github.com/apache/airflow/pull/36909#discussion_r1459398758


##########
airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py:
##########
@@ -236,7 +236,9 @@ def __init__(
         **kwargs,
     ) -> None:
         super().__init__(**kwargs)
-        self.body = deepcopy(body)
+        self.body = body
+        if isinstance(self.body, dict):
+            self.body = deepcopy(body)

Review Comment:
   The type is declared as dict and why we are handling the non dict case inside? 



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix assignment of template field in `__init__` in `CloudDataTransferServiceCreateJobOperator` [airflow]

Posted by "romsharon98 (via GitHub)" <gi...@apache.org>.
romsharon98 commented on code in PR #36909:
URL: https://github.com/apache/airflow/pull/36909#discussion_r1477279207


##########
tests/providers/google/cloud/operators/test_cloud_storage_transfer_service.py:
##########
@@ -324,21 +324,33 @@ def test_job_create_multiple(self, aws_hook, gcp_hook):
     # (could be anything else) just to test if the templating works for all
     # fields
     @pytest.mark.db_test
+    @pytest.mark.parametrize(
+        "body, excepted",
+        [
+            (
+                {"description": "{{ dag.dag_id }}"},
+                {
+                    "description": "TestGcpStorageTransferJobCreateOperator_test_templates",
+                },
+            ),
+            ("{{ dag.dag_id }}", "TestGcpStorageTransferJobCreateOperator_test_templates"),

Review Comment:
   Change to valid body



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix assignment of template field in `__init__` in `CloudDataTransferServiceCreateJobOperator` [airflow]

Posted by "romsharon98 (via GitHub)" <gi...@apache.org>.
romsharon98 commented on code in PR #36909:
URL: https://github.com/apache/airflow/pull/36909#discussion_r1461458749


##########
tests/providers/google/cloud/operators/test_cloud_storage_transfer_service.py:
##########
@@ -324,21 +324,33 @@ def test_job_create_multiple(self, aws_hook, gcp_hook):
     # (could be anything else) just to test if the templating works for all
     # fields
     @pytest.mark.db_test
+    @pytest.mark.parametrize(
+        "body, excepted",
+        [
+            (
+                {"description": "{{ dag.dag_id }}"},
+                {
+                    "description": "TestGcpStorageTransferJobCreateOperator_test_templates",
+                },
+            ),
+            ("{{ dag.dag_id }}", "TestGcpStorageTransferJobCreateOperator_test_templates"),

Review Comment:
   it's not, but it just for checking the rendering here.



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix assignment of template field in `__init__` in `CloudDataTransferServiceCreateJobOperator` [airflow]

Posted by "romsharon98 (via GitHub)" <gi...@apache.org>.
romsharon98 commented on PR #36909:
URL: https://github.com/apache/airflow/pull/36909#issuecomment-1902687616

   > Is it possible to add a test for str body?
   
   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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix assignment of template field in `__init__` in `CloudDataTransferServiceCreateJobOperator` [airflow]

Posted by "romsharon98 (via GitHub)" <gi...@apache.org>.
romsharon98 commented on code in PR #36909:
URL: https://github.com/apache/airflow/pull/36909#discussion_r1461458749


##########
tests/providers/google/cloud/operators/test_cloud_storage_transfer_service.py:
##########
@@ -324,21 +324,33 @@ def test_job_create_multiple(self, aws_hook, gcp_hook):
     # (could be anything else) just to test if the templating works for all
     # fields
     @pytest.mark.db_test
+    @pytest.mark.parametrize(
+        "body, excepted",
+        [
+            (
+                {"description": "{{ dag.dag_id }}"},
+                {
+                    "description": "TestGcpStorageTransferJobCreateOperator_test_templates",
+                },
+            ),
+            ("{{ dag.dag_id }}", "TestGcpStorageTransferJobCreateOperator_test_templates"),

Review Comment:
   it's not, but this test just checking the rendering.
   You are right, I think moving this line:
   https://github.com/apache/airflow/blob/d77f115ebc37613a48563a760a2df4e01f604335/airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py#L247
   to the begging of the execute will solve it, what do you think?



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix assignment of template field in `__init__` in `CloudDataTransferServiceCreateJobOperator` [airflow]

Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala commented on code in PR #36909:
URL: https://github.com/apache/airflow/pull/36909#discussion_r1461039353


##########
tests/providers/google/cloud/operators/test_cloud_storage_transfer_service.py:
##########
@@ -324,21 +324,33 @@ def test_job_create_multiple(self, aws_hook, gcp_hook):
     # (could be anything else) just to test if the templating works for all
     # fields
     @pytest.mark.db_test
+    @pytest.mark.parametrize(
+        "body, excepted",
+        [
+            (
+                {"description": "{{ dag.dag_id }}"},
+                {
+                    "description": "TestGcpStorageTransferJobCreateOperator_test_templates",
+                },
+            ),
+            ("{{ dag.dag_id }}", "TestGcpStorageTransferJobCreateOperator_test_templates"),

Review Comment:
   Is this a valid body?
   https://github.com/apache/airflow/blob/d77f115ebc37613a48563a760a2df4e01f604335/airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py#L249-L250



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix assignment of template field in `__init__` in `CloudDataTransferServiceCreateJobOperator` [airflow]

Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala merged PR #36909:
URL: https://github.com/apache/airflow/pull/36909


-- 
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: commits-unsubscribe@airflow.apache.org

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