This is an automated email from the ASF dual-hosted git repository.
shahar1 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 b6f72cd1874 Fix WeaviateIngestOperator input_data validation before
rendering (#70326)
b6f72cd1874 is described below
commit b6f72cd1874ca84578bf052af3a1d5cd3808cb18
Author: Parman Mohammadalizadeh <[email protected]>
AuthorDate: Fri Jul 24 19:10:43 2026 +0330
Fix WeaviateIngestOperator input_data validation before rendering (#70326)
* Fix WeaviateIngestOperator input_data validation before rendering
input_data is a template field, rendered after __init__ runs. Validating
it in the constructor checks the un-rendered value. Move the required-value
check into execute() so it runs on the rendered value. Constructing with
input_data=None now raises at run time rather than at build time.
* Make WeaviateIngestOperator input_data a required argument
The default was left over from the removed input_json alternative. Dropping
it
restores parse-time validation of a missing input_data through Python
itself and
lets mypy catch input_data=None, while the execute() check still guards
values
that render to None after templating.
---
.../src/airflow/providers/weaviate/operators/weaviate.py | 7 +++----
.../tests/unit/weaviate/operators/test_weaviate.py | 15 +++++++++++++++
scripts/ci/prek/validate_operators_init_exemptions.txt | 1 -
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git
a/providers/weaviate/src/airflow/providers/weaviate/operators/weaviate.py
b/providers/weaviate/src/airflow/providers/weaviate/operators/weaviate.py
index de080c72320..a52317393f0 100644
--- a/providers/weaviate/src/airflow/providers/weaviate/operators/weaviate.py
+++ b/providers/weaviate/src/airflow/providers/weaviate/operators/weaviate.py
@@ -59,7 +59,7 @@ class WeaviateIngestOperator(BaseOperator):
self,
conn_id: str,
collection_name: str,
- input_data: list[dict[str, Any]] | pd.DataFrame | None = None,
+ input_data: list[dict[str, Any]] | pd.DataFrame,
vector_col: str = "Vector",
uuid_column: str = "id",
tenant: str | None = None,
@@ -75,15 +75,14 @@ class WeaviateIngestOperator(BaseOperator):
self.input_data = input_data
self.hook_params = hook_params or {}
- if self.input_data is None:
- raise TypeError("input_data is required")
-
@cached_property
def hook(self) -> WeaviateHook:
"""Return an instance of the WeaviateHook."""
return WeaviateHook(conn_id=self.conn_id, **self.hook_params)
def execute(self, context: Context) -> None:
+ if self.input_data is None:
+ raise TypeError("input_data is required")
self.log.debug("Input data: %s", self.input_data)
self.hook.batch_data(
collection_name=self.collection_name,
diff --git a/providers/weaviate/tests/unit/weaviate/operators/test_weaviate.py
b/providers/weaviate/tests/unit/weaviate/operators/test_weaviate.py
index 0f09fb35d52..dbb94265f81 100644
--- a/providers/weaviate/tests/unit/weaviate/operators/test_weaviate.py
+++ b/providers/weaviate/tests/unit/weaviate/operators/test_weaviate.py
@@ -81,6 +81,21 @@ class TestWeaviateIngestOperator:
tenant="tenant-a",
)
+ def test_missing_input_data_raises_at_execute_not_init(self):
+ """
+ input_data is a template field, so the required-value check runs in
execute()
+ (after rendering), not in __init__. Constructing with input_data=None
must not raise.
+ """
+ operator = WeaviateIngestOperator(
+ task_id="weaviate_task",
+ conn_id="weaviate_conn",
+ collection_name="my_collection",
+ input_data=None,
+ )
+
+ with pytest.raises(TypeError, match="input_data is required"):
+ operator.execute(context=None)
+
@pytest.mark.db_test
def test_templates(self, create_task_instance_of_operator):
dag_id = "TestWeaviateIngestOperator"
diff --git a/scripts/ci/prek/validate_operators_init_exemptions.txt
b/scripts/ci/prek/validate_operators_init_exemptions.txt
index 71a13973e4c..b78123db0dc 100644
--- a/scripts/ci/prek/validate_operators_init_exemptions.txt
+++ b/scripts/ci/prek/validate_operators_init_exemptions.txt
@@ -69,4 +69,3 @@
providers/ssh/src/airflow/providers/ssh/operators/ssh_remote_job.py::SSHRemoteJo
providers/standard/src/airflow/providers/standard/operators/bash.py::BashOperator
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.py::TriggerDagRunOperator
providers/standard/src/airflow/providers/standard/sensors/date_time.py::DateTimeSensor
-providers/weaviate/src/airflow/providers/weaviate/operators/weaviate.py::WeaviateIngestOperator