Skip to content

Commit

Permalink
Update based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnucoder1 committed Nov 23, 2023
1 parent a00f559 commit 18f2dba
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 49 deletions.
7 changes: 5 additions & 2 deletions airflow/models/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
from airflow.utils.dag_cycle_tester import check_cycle
from airflow.utils.dates import cron_presets, date_range as utils_date_range
from airflow.utils.decorators import fixup_decorator_warning_stack
from airflow.utils.helpers import at_least_one, at_most_one, exactly_one, validate_key
from airflow.utils.helpers import at_most_one, exactly_one, validate_key
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.session import NEW_SESSION, provide_session
from airflow.utils.sqlalchemy import (
Expand Down Expand Up @@ -549,7 +549,10 @@ def __init__(
# sort out DAG's scheduling behavior
scheduling_args = [schedule_interval, timetable, schedule]

if at_least_one(*scheduling_args) and not ("start_date" in self.default_args or self.start_date):
has_scheduling_args = any(a is not NOTSET and bool(a) for a in scheduling_args)
has_empty_start_date = not ("start_date" in self.default_args or self.start_date)

if has_scheduling_args and has_empty_start_date:
raise ValueError("DAG is missing the start_date parameter")

if not at_most_one(*scheduling_args):
Expand Down
18 changes: 0 additions & 18 deletions airflow/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,24 +325,6 @@ def is_set(val):
return sum(map(is_set, args)) in (0, 1)


def at_least_one(*args) -> bool:
"""
Return True if at least one of *args is "truthy", and False otherwise.
NOTSET is treated the same as None.
If user supplies an iterable, we raise ValueError and force them to unpack.
"""

def is_set(val):
if val is NOTSET:
return False
else:
return bool(val)

return sum(map(is_set, args)) > 0


def prune_dict(val: Any, mode="strict"):
"""
Given dict ``val``, returns new dict based on ``val`` with all empty elements removed.
Expand Down
29 changes: 0 additions & 29 deletions tests/utils/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from airflow.jobs.base_job_runner import BaseJobRunner
from airflow.utils import helpers, timezone
from airflow.utils.helpers import (
at_least_one,
at_most_one,
build_airflow_url_with_query,
exactly_one,
Expand Down Expand Up @@ -304,34 +303,6 @@ def assert_at_most_one(true=0, truthy=0, false=0, falsy=0, notset=0):
print(row)
assert_at_most_one(*row)

def test_at_least_one(self):
"""
Checks that when we set ``true_count`` elements to "truthy", and others to "falsy",
we get the expected return.
We check for both True / False, and truthy / falsy values 'a' and '', and verify that
they can safely be used in any combination.
NOTSET values should be ignored.
"""

def assert_at_least_one(true=0, truthy=0, false=0, falsy=0, notset=0):
sample = []
for truth_value, num in [
(True, true),
(False, false),
("a", truthy),
("", falsy),
(NOTSET, notset),
]:
if num:
sample.extend([truth_value] * num)
if sample:
expected = True if true + truthy > 0 else False
assert at_least_one(*sample) is expected

for row in itertools.product(range(4), repeat=4):
print(row)
assert_at_least_one(*row)

@pytest.mark.parametrize(
"mode, expected",
[
Expand Down

0 comments on commit 18f2dba

Please sign in to comment.