This is an automated email from the ASF dual-hosted git repository.
potiuk 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 a75366e1828 Rewrite SnowparkContainerJobOperator exclusivity check and
move back to __init__ (#70874)
a75366e1828 is described below
commit a75366e1828c2a36ae0d48edf2d0a08b53d42ac8
Author: ahilashsasidharan <[email protected]>
AuthorDate: Fri Jul 31 20:46:00 2026 -0400
Rewrite SnowparkContainerJobOperator exclusivity check and move back to
__init__ (#70874)
---
.../providers/snowflake/operators/snowpark_containers.py | 4 ++--
.../unit/snowflake/operators/test_snowpark_containers.py | 11 +++++------
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git
a/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
b/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
index 1564e57b997..ac8e536b920 100644
---
a/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
+++
b/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
@@ -144,6 +144,8 @@ class SnowparkContainerJobOperator(BaseOperator):
**kwargs: Any,
) -> None:
super().__init__(**kwargs)
+ if spec_text is not None and (spec is not None or spec_stage is not
None):
+ raise ValueError("Cannot specify both 'spec_text' and
'spec'/'spec_stage'")
self.compute_pool = compute_pool
self.container_name = container_name
self.spec = spec
@@ -232,8 +234,6 @@ class SnowparkContainerJobOperator(BaseOperator):
def execute(self, context: Context) -> str:
"""Submit and optionally wait for a Snowpark Container Services job."""
- if self.spec_text and (self.spec or self.spec_stage):
- raise ValueError("Cannot specify both 'spec_text' and
'spec'/'spec_stage'")
if not self.spec_text and not (self.spec and self.spec_stage):
raise ValueError("Must provide either 'spec_text' or both 'spec'
and 'spec_stage'")
diff --git
a/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
b/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
index af6114f6616..c154c529025 100644
---
a/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
+++
b/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
@@ -46,6 +46,10 @@ def _make_operator(**kwargs):
class TestSnowparkContainerJobOperator:
+ def test_invalid_spec_combinations_at_init(self):
+ with pytest.raises(ValueError, match=r"Cannot specify both"):
+ _make_operator(spec=SPEC, spec_stage=SPEC_STAGE,
spec_text=SPEC_TEXT)
+
@pytest.mark.parametrize(
("kwargs", "match"),
(
@@ -54,11 +58,6 @@ class TestSnowparkContainerJobOperator:
"Must provide either",
id="no_spec_provided",
),
- pytest.param(
- {"spec": SPEC, "spec_stage": SPEC_STAGE, "spec_text":
SPEC_TEXT},
- "Cannot specify both",
- id="both_spec_and_spec_text",
- ),
pytest.param(
{"spec": SPEC, "spec_stage": None, "spec_text": None},
"Must provide either",
@@ -71,7 +70,7 @@ class TestSnowparkContainerJobOperator:
),
),
)
- def test_invalid_spec_combinations(self, kwargs, match):
+ def test_invalid_spec_combinations_at_execute(self, kwargs, match):
op = _make_operator(**kwargs)
with pytest.raises(ValueError, match=match):
op.execute(context=None)