Skip to content

Commit

Permalink
Update the error message for invalid use of poke-only sensors (#30821)
Browse files Browse the repository at this point in the history
(cherry picked from commit cbaea57)
  • Loading branch information
dakshin-k authored and ephraimbuddy committed Apr 23, 2023
1 parent c0cda4e commit 62223b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion airflow/sensors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def mode_getter(_):

def mode_setter(_, value):
if value != "poke":
raise ValueError("cannot set mode to 'poke'.")
raise ValueError(f"Cannot set mode to '{value}'. Only 'poke' is acceptable")

if not issubclass(cls_type, BaseSensorOperator):
raise ValueError(
Expand Down
6 changes: 3 additions & 3 deletions tests/sensors/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,14 +862,14 @@ def test_poke_mode_only_allows_poke_mode(self):

def test_poke_mode_only_bad_class_method(self):
sensor = DummyPokeOnlySensor(task_id="foo", mode="poke", poke_changes_mode=False)
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="Cannot set mode to 'reschedule'. Only 'poke' is acceptable"):
sensor.change_mode("reschedule")

def test_poke_mode_only_bad_init(self):
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="Cannot set mode to 'reschedule'. Only 'poke' is acceptable"):
DummyPokeOnlySensor(task_id="foo", mode="reschedule", poke_changes_mode=False)

def test_poke_mode_only_bad_poke(self):
sensor = DummyPokeOnlySensor(task_id="foo", mode="poke", poke_changes_mode=True)
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="Cannot set mode to 'reschedule'. Only 'poke' is acceptable"):
sensor.poke({})

0 comments on commit 62223b5

Please sign in to comment.