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

[PR] Static Checks: Exception statement has no effect [airflow]

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

   <!--
    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/
   -->
   
   During some code review I've accidentally found sometimes we do not raise an error or warning in our code.
   Unfortunetly there is no such of check into the ruff, suggested [`B018`](https://github.com/astral-sh/ruff/issues/8674) can't detect this cases, so I propose to run this kind of check ([`W0133`](https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/pointless-exception-statement.html)) by `pylint`, and only this one.
   
   <!-- 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-docs/05_pull_requests.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] Static Checks: Exception statement has no effect [airflow]

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


##########
airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py:
##########
@@ -546,28 +547,29 @@ def __init__(
     ) -> None:
         # To preserve backward compatibility
         # TODO: remove one day

Review Comment:
   Move this removal into the separate PR



-- 
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] Static Checks: Exception statement has no effect [airflow]

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

   We should open an issue on Ruff for this.


-- 
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] Static Checks: Exception statement has no effect [airflow]

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

   I was a **little** sceptical. We removed pylint **gladly** when we introduced ruff. Rather than introducing new tool for that, I'd  generally wait until ruff supports such rule. 
   But with that very specific rule - I see that "full check" is extremely fast. so yeah, let's do 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 "Exception statement has no effect" [airflow]

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

   I am fine. It's fast, easy to remove


-- 
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] Static Checks: Exception statement has no effect [airflow]

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

   > I could open issue/feature request at ruff repo with appropriate example when neither ruff B018 or flake8-bugbear doesn't work. Maybe one day it would be added into the ruff, so we could remove pylint again
   
   >  We should open an issue on Ruff for this.
   
   Yes. Yes. 
   


-- 
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] Static Checks: Exception statement has no effect [airflow]

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


##########
airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py:
##########
@@ -546,28 +547,29 @@ def __init__(
     ) -> None:
         # To preserve backward compatibility
         # TODO: remove one day
+        _filter = kwargs.pop("filter", None)
         if request_filter is None:
-            if "filter" in kwargs:
-                request_filter = kwargs["filter"]
-                AirflowProviderDeprecationWarning(
-                    "Use 'request_filter' instead 'filter' to pass the argument."
-                )
-            else:
-                TypeError("__init__() missing 1 required positional argument: 'request_filter'")
-
+            if not _filter:
+                raise ValueError("'request_filter' should be set")
+            request_filter = _filter
+            warnings.warn(
+                "Use 'request_filter' instead 'filter' to pass the argument.",
+                AirflowProviderDeprecationWarning,
+                stacklevel=2,
+            )
         super().__init__(**kwargs)
         self.filter = request_filter
         self.project_id = project_id
         self.gcp_conn_id = gcp_conn_id
         self.api_version = api_version
         self.google_impersonation_chain = google_impersonation_chain
-        self._validate_inputs()
 
     def _validate_inputs(self) -> None:
         if not self.filter:
             raise AirflowException("The required parameter 'filter' is empty or None")
 
     def execute(self, context: Context) -> list[dict]:
+        self._validate_inputs()

Review Comment:
   Templated field could rendered into the empty value, and we know it only after render this value



-- 
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] Static Checks: Exception statement has no effect [airflow]

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


##########
airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py:
##########
@@ -546,28 +547,29 @@ def __init__(
     ) -> None:
         # To preserve backward compatibility
         # TODO: remove one day
+        _filter = kwargs.pop("filter", None)
         if request_filter is None:
-            if "filter" in kwargs:
-                request_filter = kwargs["filter"]
-                AirflowProviderDeprecationWarning(
-                    "Use 'request_filter' instead 'filter' to pass the argument."
-                )
-            else:
-                TypeError("__init__() missing 1 required positional argument: 'request_filter'")
-
+            if not _filter:
+                raise ValueError("'request_filter' should be set")
+            request_filter = _filter
+            warnings.warn(
+                "Use 'request_filter' instead 'filter' to pass the argument.",
+                AirflowProviderDeprecationWarning,
+                stacklevel=2,
+            )
         super().__init__(**kwargs)
         self.filter = request_filter
         self.project_id = project_id
         self.gcp_conn_id = gcp_conn_id
         self.api_version = api_version
         self.google_impersonation_chain = google_impersonation_chain
-        self._validate_inputs()
 
     def _validate_inputs(self) -> None:
         if not self.filter:
             raise AirflowException("The required parameter 'filter' is empty or None")
 
     def execute(self, context: Context) -> list[dict]:
+        self._validate_inputs()

Review Comment:
   Small clarification. Why we moved _validate_inputs from init to execute method?



-- 
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 "Exception statement has no effect" [airflow]

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

   Just to be on the same page. We do not have any objections to temporary include `pylint` into our static check until this rule not implemented into the ruff?


-- 
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 "Exception statement has no effect" [airflow]

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


-- 
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] Static Checks: Exception statement has no effect [airflow]

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


##########
airflow/providers/google/cloud/transfers/gcs_to_local.py:
##########
@@ -87,13 +88,17 @@ def __init__(
     ) -> None:
         # To preserve backward compatibility
         # TODO: Remove one day

Review Comment:
   Same here



##########
airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py:
##########
@@ -546,28 +547,29 @@ def __init__(
     ) -> None:
         # To preserve backward compatibility
         # TODO: remove one day

Review Comment:
   I'm pretty sure that this fallback broken for a long time, this part exists before this code migrated from the `airflow.contrib` to the `providers` in https://github.com/apache/airflow/pull/6077 I do not trace this change back.
   
   `filter` parameter keep into the `kwargs` and pass to subclass and this will raise an error that parameter not defined.
   
   So another option just remove entire fallback block, since it do not work well for more than 3-4 years.



-- 
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] Static Checks: Exception statement has no effect [airflow]

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

   I'm also not happy to have another linter, but yeah seems like this single rule work pretty fast.
   
   I could open issue/feature request at ruff repo with appropriate example when neither `ruff` B018 or `flake8-bugbear` doesn't work. Maybe one day it would be added into the ruff, so we could remove `pylint` again


-- 
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] Static Checks: Exception statement has no effect [airflow]

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


##########
airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py:
##########
@@ -546,28 +547,29 @@ def __init__(
     ) -> None:
         # To preserve backward compatibility
         # TODO: remove one day

Review Comment:
   Remove 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] Static Checks: Exception statement has no effect [airflow]

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


##########
airflow/providers/google/cloud/transfers/gcs_to_local.py:
##########
@@ -87,13 +88,17 @@ def __init__(
     ) -> None:
         # To preserve backward compatibility
         # TODO: Remove one day

Review Comment:
   same



-- 
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] Static Checks: Exception statement has no effect [airflow]

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

   I've just created new rule request at ruff GitHub Issues: https://github.com/astral-sh/ruff/issues/10145


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