From ae9c7a1a6a17ee6adde9fe9de4f6a3905ec9d2a6 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Thu, 17 Oct 2024 14:49:29 -0700 Subject: [PATCH] Validate that `--event-time-start` and `--event-time-end` are mutually present --- core/dbt/cli/flags.py | 18 +++++++++++++++++- .../cli/test_option_interaction_validations.py | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/core/dbt/cli/flags.py b/core/dbt/cli/flags.py index 1b73e6ba159..21fd660460f 100644 --- a/core/dbt/cli/flags.py +++ b/core/dbt/cli/flags.py @@ -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`" diff --git a/tests/functional/cli/test_option_interaction_validations.py b/tests/functional/cli/test_option_interaction_validations.py index dee422c0fe1..3cee244aedd 100644 --- a/tests/functional/cli/test_option_interaction_validations.py +++ b/tests/functional/cli/test_option_interaction_validations.py @@ -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__() + )