This is an automated email from the ASF dual-hosted git repository.
eladkal pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 086361bf3f0 Show the deprecated Neo4jOperator sql query in Rendered
Templates (#70373)
086361bf3f0 is described below
commit 086361bf3f0798baea3d5c88b282651b38ce4519
Author: Shahar Epstein <[email protected]>
AuthorDate: Fri Jul 24 13:49:07 2026 +0300
Show the deprecated Neo4jOperator sql query in Rendered Templates (#70373)
The sql parameter is a deprecated alias for cypher. It used to be folded
into
cypher in the constructor, so it was rendered by the normal template-field
machinery and the resolved query appeared in the Rendered Templates view.
It is
now kept as a separate attribute that is not a template field and is
rendered by
an ad-hoc render_template() call inside execute(), so the view shows an
empty
cypher while a different query runs, and the rendering bypasses the standard
pipeline.
Declaring sql as a template field lets the framework render it as it does
every
other field. The deprecation warning moves to execute() because a
constructor
only ever sees the un-rendered Jinja expression of a template field.
---
.../src/airflow/providers/neo4j/operators/neo4j.py | 17 ++++++++---------
.../neo4j/tests/unit/neo4j/operators/test_neo4j.py | 14 +++++++-------
2 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/providers/neo4j/src/airflow/providers/neo4j/operators/neo4j.py
b/providers/neo4j/src/airflow/providers/neo4j/operators/neo4j.py
index 0c2a6538ad4..e0d1e1b1538 100644
--- a/providers/neo4j/src/airflow/providers/neo4j/operators/neo4j.py
+++ b/providers/neo4j/src/airflow/providers/neo4j/operators/neo4j.py
@@ -44,8 +44,8 @@ class Neo4jOperator(BaseOperator):
:param parameters: the parameters to send to Neo4j driver session
"""
- template_fields: Sequence[str] = ("cypher", "parameters")
- template_fields_renderers = {"cypher": "sql", "parameters": "json"}
+ template_fields: Sequence[str] = ("cypher", "sql", "parameters")
+ template_fields_renderers = {"cypher": "sql", "sql": "sql", "parameters":
"json"}
def __init__(
self,
@@ -57,12 +57,6 @@ class Neo4jOperator(BaseOperator):
**kwargs,
) -> None:
super().__init__(**kwargs)
- if sql is not None:
- warnings.warn(
- "`sql` parameter is deprecated, please use `cypher` instead.",
- AirflowProviderDeprecationWarning,
- stacklevel=2,
- )
self.neo4j_conn_id = neo4j_conn_id
self.cypher = cypher
self.sql = sql
@@ -71,9 +65,14 @@ class Neo4jOperator(BaseOperator):
def execute(self, context: Context) -> None:
cypher = self.cypher
if self.sql is not None:
+ warnings.warn(
+ "`sql` parameter is deprecated, please use `cypher` instead.",
+ AirflowProviderDeprecationWarning,
+ stacklevel=2,
+ )
if cypher is not None:
raise ValueError("Cannot provide both `sql` and `cypher`. Use
`cypher` only.")
- cypher = self.render_template(self.sql, context)
+ cypher = self.sql
if cypher is None:
raise ValueError("Parameter `cypher` is required.")
diff --git a/providers/neo4j/tests/unit/neo4j/operators/test_neo4j.py
b/providers/neo4j/tests/unit/neo4j/operators/test_neo4j.py
index 3cebcfaffcb..3399cdb6cce 100644
--- a/providers/neo4j/tests/unit/neo4j/operators/test_neo4j.py
+++ b/providers/neo4j/tests/unit/neo4j/operators/test_neo4j.py
@@ -57,21 +57,21 @@ class TestNeo4jOperator:
cypher = """
MATCH (tom {name: "Tom Hanks"}) RETURN tom
"""
+ op = Neo4jOperator(task_id="basic_neo4j", sql=cypher)
+ assert "sql" in op.template_fields
with pytest.warns(
AirflowProviderDeprecationWarning,
match="`sql` parameter is deprecated, please use `cypher`
instead.",
):
- op = Neo4jOperator(task_id="basic_neo4j", sql="{{ cypher }}")
- assert op.sql == "{{ cypher }}"
- op.execute({"cypher": cypher})
+ op.execute(mock.MagicMock())
mock_hook.return_value.run.assert_called_once_with(cypher, None)
def test_neo4j_operator_both_sql_and_cypher_raises_on_execute(self):
- with pytest.warns(AirflowProviderDeprecationWarning):
- op = Neo4jOperator(task_id="basic_neo4j", sql="a", cypher="b")
+ op = Neo4jOperator(task_id="basic_neo4j", sql="a", cypher="b")
- with pytest.raises(ValueError, match="Cannot provide both `sql` and
`cypher`"):
- op.execute(mock.MagicMock())
+ with pytest.warns(AirflowProviderDeprecationWarning):
+ with pytest.raises(ValueError, match="Cannot provide both `sql`
and `cypher`"):
+ op.execute(mock.MagicMock())
def test_neo4j_operator_missing_cypher_raises_on_execute(self):
op = Neo4jOperator(task_id="basic_neo4j")