Skip to content

Commit

Permalink
Validate that --event-time-start and --event-time-end are mutuall…
Browse files Browse the repository at this point in the history
…y present
  • Loading branch information
QMalcolm committed Oct 17, 2024
1 parent 6973e66 commit ae9c7a1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
18 changes: 17 additions & 1 deletion core/dbt/cli/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,23 @@ def _validate_event_time_configs(self) -> None:
getattr(self, "EVENT_TIME_END") if hasattr(self, "EVENT_TIME_END") else None
)

if event_time_start is not None and event_time_end is not None:
# only do validations if at least one of `event_time_start` or `event_time_end` are specified
if event_time_start is not None or event_time_end is not None:

# These `ifs`, combined with the parent `if` make it so that `event_time_start` and
# `event_time_end` are mutually required
if event_time_start is None:
raise DbtUsageException(
"The flag `--event-time-end` was specified, but `--event-time-start` was not. "
"When specifying `--event-time-end`, `--event-time-start` must also be present."
)
if event_time_end is None:
raise DbtUsageException(
"The flag `--event-time-start` was specified, but `--event-time-end` was not. "
"When specifying `--event-time-start`, `--event-time-end` must also be present."
)

# This `if` just is a sanity check that `event_time_start` is before `event_time_end`
if event_time_start >= event_time_end:
raise DbtUsageException(
"Value for `--event-time-start` must be less than `--event-time-end`"
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/cli/test_option_interaction_validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@ def test_option_combo(self, project, event_time_start, event_time_end, expect_pa
in e.__str__()
)
assert not expect_pass


class TestEventTimeEndEventTimeStartMutuallyRequired:
@pytest.mark.parametrize(
"specified,missing",
[
("--event-time-start", "--event-time-end"),
("--event-time-end", "--event-time-start"),
],
)
def test_option_combo(self, project, specified, missing):
try:
run_dbt(["build", specified, "2024-10-01"])
assert False, f"An error should have been raised for missing `{missing}` flag"
except Exception as e:
assert (
f"When specifying `{specified}`, `{missing}` must also be present." in e.__str__()
)

0 comments on commit ae9c7a1

Please sign in to comment.