This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch v3-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-0-test by this push:
new d571f5ba160 [v3-0-test] Remove unnecessary session checks and improve
the message (#54843) (#54844)
d571f5ba160 is described below
commit d571f5ba160ca7dc24c089403f2df76c829cf807
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Aug 22 22:01:43 2025 +0200
[v3-0-test] Remove unnecessary session checks and improve the message
(#54843) (#54844)
(cherry picked from commit b0e8042b81594e9f5643505fd8a561f45c8c974d)
Co-authored-by: Pratiksha <[email protected]>
---
.../ci/prek/prevent_deprecated_sqlalchemy_usage.py | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/scripts/ci/prek/prevent_deprecated_sqlalchemy_usage.py
b/scripts/ci/prek/prevent_deprecated_sqlalchemy_usage.py
index c26e7d24758..e85292d8b35 100644
--- a/scripts/ci/prek/prevent_deprecated_sqlalchemy_usage.py
+++ b/scripts/ci/prek/prevent_deprecated_sqlalchemy_usage.py
@@ -26,30 +26,26 @@ from rich.console import Console
console = Console(color_system="standard", width=200)
-def check_session_query(mod: ast.Module, file_path: str) -> int:
+def check_session_query(mod: ast.Module, file_path: str) -> bool:
errors = False
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"\nUse of legacy `session.query` detected on line
{node.lineno} in {file_path} "
- f"\nSQLAlchemy 2.0 deprecates the `Query` object"
- f"use the `select()` construct instead."
- )
+ if node.func.attr == "query":
+ console.print(f"Deprecated query-obj found at line
{node.lineno} in {file_path}.")
errors = True
return errors
def main():
+ exit_code = 0
for file in sys.argv[1:]:
file_path = Path(file)
ast_module = ast.parse(file_path.read_text(encoding="utf-8"), file)
errors = check_session_query(ast_module, file_path)
- return 1 if errors else 0
+ if errors:
+ exit_code = 1
+ console.print("[yellow]Please update SQLAlchemy 2.0 style.\n")
+ return exit_code
if __name__ == "__main__":