You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Prab-27 (via GitHub)" <gi...@apache.org> on 2025/01/16 17:14:41 UTC
[PR] Add pre-commit To Prevent Usage of session.query In Core Airflow [airflow]
Prab-27 opened a new pull request, #45714:
URL: https://github.com/apache/airflow/pull/45714
closes : #45461
Introduce a pre-commit hook to prevent the use of `session.query` in the core Airflow code.
This is limited to the source code and excludes the tests/ package.
<!--
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-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] Add pre-commit To Prevent Usage of session.query In Core Airflow [airflow]
Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #45714:
URL: https://github.com/apache/airflow/pull/45714#discussion_r1920491423
##########
scripts/ci/pre_commit/usage_session_attribute.py:
##########
@@ -0,0 +1,55 @@
+# 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.
+
+from __future__ import annotations
+
+import ast
+import sys
+from pathlib import Path
+
+from rich.console import Console
+
+console = Console(color_system="standard", width=200)
+
+
+def check_session_query(mod: ast.Module) -> int:
+ errors = 0
+ for node in ast.walk(mod):
+ if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute):
+ if (
+ node.func.attr == "query"
+ and isinstance(node.func.value, ast.Name)
+ and node.func.value.id == "session"
+ ):
+ console.print(f"Remove session.query from line {node.lineno}")
+ errors += 1
+ return errors
+
+
+def main():
+ for file in sys.argv[1:]:
+ file_path = Path(file)
+ if file_path.name.startswith("test_"):
+ continue
Review Comment:
Done!
--
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] Add pre-commit To Prevent Usage of session.query In Core Airflow [airflow]
Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on PR #45714:
URL: https://github.com/apache/airflow/pull/45714#issuecomment-2692753439
Sorry I have to close this 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] Add pre-commit To Prevent Usage of session.query In Core Airflow [airflow]
Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on PR #45714:
URL: https://github.com/apache/airflow/pull/45714#issuecomment-2596354814
a conflict occurred with the images, and I'm not sure how to resolve it. Would you please help me?
--
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] Add pre-commit To Prevent Usage of session.query In Core Airflow [airflow]
Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #45714:
URL: https://github.com/apache/airflow/pull/45714#discussion_r1920491145
##########
scripts/ci/pre_commit/usage_session_attribute.py:
##########
@@ -0,0 +1,55 @@
+# 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.
+
+from __future__ import annotations
+
+import ast
+import sys
+from pathlib import Path
+
+from rich.console import Console
+
+console = Console(color_system="standard", width=200)
+
+
+def check_session_query(mod: ast.Module) -> int:
+ errors = 0
+ for node in ast.walk(mod):
+ if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute):
+ if (
+ node.func.attr == "query"
+ and isinstance(node.func.value, ast.Name)
+ and node.func.value.id == "session"
+ ):
+ console.print(f"Remove session.query from line {node.lineno}")
Review Comment:
Done !
I tried to write msg from [session.query](https://docs.sqlalchemy.org/en/20/orm/session_api.html#sqlalchemy.orm.Session.query)
IS it okay ?
--
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] Add pre-commit To Prevent Usage of session.query In Core Airflow [airflow]
Posted by "ephraimbuddy (via GitHub)" <gi...@apache.org>.
ephraimbuddy commented on PR #45714:
URL: https://github.com/apache/airflow/pull/45714#issuecomment-2665753274
> Could you please clarify it for me? 1 Is it okay to include` providers` in this pre-commit hook ? 2 Do I need to remove `session.query` from the codebases to pass this pre-commit check ?
Providers should not be part of this. You have to specify that this should check in airflow/ and task_sdk/ and not providers/.
You also need to remove all usage of session.query for this to pass. Sorry for this late reply
--
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] Add pre-commit To Prevent Usage of session.query In Core Airflow [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #45714:
URL: https://github.com/apache/airflow/pull/45714#issuecomment-2596844944
as explained in slack - you can replace the confilcting images / .txt with either versions, rebase and re-run pre-commit. The images wil get regenerated to be "latest" automatically (in fact it should happen automatically when you rebase your PR and resolve the conflicts if you did `pre-commit install` before).
--
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] Add pre-commit To Prevent Usage of session.query In Core Airflow [airflow]
Posted by "ephraimbuddy (via GitHub)" <gi...@apache.org>.
ephraimbuddy commented on code in PR #45714:
URL: https://github.com/apache/airflow/pull/45714#discussion_r1920059493
##########
scripts/ci/pre_commit/usage_session_attribute.py:
##########
@@ -0,0 +1,55 @@
+# 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.
+
+from __future__ import annotations
+
+import ast
+import sys
+from pathlib import Path
+
+from rich.console import Console
+
+console = Console(color_system="standard", width=200)
+
+
+def check_session_query(mod: ast.Module) -> int:
+ errors = 0
+ for node in ast.walk(mod):
+ if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute):
+ if (
+ node.func.attr == "query"
+ and isinstance(node.func.value, ast.Name)
+ and node.func.value.id == "session"
+ ):
+ console.print(f"Remove session.query from line {node.lineno}")
Review Comment:
We are removing the session.query because it is deprecated in SQLAlchemy 2. The message should reflect this and suggest that the user use the new-style query constructs.
##########
scripts/ci/pre_commit/usage_session_attribute.py:
##########
@@ -0,0 +1,55 @@
+# 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.
+
+from __future__ import annotations
+
+import ast
+import sys
+from pathlib import Path
+
+from rich.console import Console
+
+console = Console(color_system="standard", width=200)
+
+
+def check_session_query(mod: ast.Module) -> int:
+ errors = 0
+ for node in ast.walk(mod):
+ if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute):
+ if (
+ node.func.attr == "query"
+ and isinstance(node.func.value, ast.Name)
+ and node.func.value.id == "session"
+ ):
+ console.print(f"Remove session.query from line {node.lineno}")
+ errors += 1
+ return errors
+
+
+def main():
+ for file in sys.argv[1:]:
+ file_path = Path(file)
+ if file_path.name.startswith("test_"):
+ continue
Review Comment:
This check for tests file is not necessary because you have the files to look for at the pre-commit-config.yaml entry
--
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] Add pre-commit To Prevent Usage of session.query In Core Airflow [airflow]
Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on PR #45714:
URL: https://github.com/apache/airflow/pull/45714#issuecomment-2599459949
Could you please clarify it for me?
1 Is it okay to include` providers` in this pre-commit in this hook ?
2 Do I need to remove `session.query` from the codebases to pass this pre-commit check ?
--
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] Add pre-commit To Prevent Usage of session.query In Core Airflow [airflow]
Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 closed pull request #45714: Add pre-commit To Prevent Usage of session.query In Core Airflow
URL: https://github.com/apache/airflow/pull/45714
--
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