-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Validate that `event_time_start` is before `event_time_end` when passed from CLI Sometimes CLI options have restrictions based on other CLI options. This is the case for `--event-time-start` and `--event-time-end`. Unfortunately, click doesn't provide a good way for validating this, at least not that I found. Additionaly I'm not sure if we have had anything like this previously. In any case, I couldn't find a centralized validation area for such occurances. Thus I've gone and added one, `validate_option_interactions`. Long term if more validations are added, we should add this wrapper to each CLI command. For now I've only added it to the commands that support `event_time_start` and `event_time_end`, specifically `build` and `run`. * Add changie doc * If `--event-time-end` is not specififed, ensure `--event-time-start` is less than the current time * Fixup error message about event_time_start and event_time_end * Move logic to validate `event_time` cli flags to `flags.py` * Update validation of `--event-time-start` against `datetime.now` to use UTC
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Ensure `--event-time-start` is before `--event-time-end` | ||
time: 2024-10-03T17:05:29.984398-05:00 | ||
custom: | ||
Author: QMalcolm | ||
Issue: "10786" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tests/functional/cli/test_option_interaction_validations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from datetime import datetime | ||
|
||
import pytest | ||
from freezegun import freeze_time | ||
|
||
from dbt.tests.util import run_dbt | ||
|
||
|
||
class TestEventTimeEndEventTimeStart: | ||
@pytest.mark.parametrize( | ||
"event_time_start,event_time_end,expect_pass", | ||
[ | ||
("2024-10-01", "2024-10-02", True), | ||
("2024-10-02", "2024-10-01", False), | ||
], | ||
) | ||
def test_option_combo(self, project, event_time_start, event_time_end, expect_pass): | ||
try: | ||
run_dbt( | ||
[ | ||
"build", | ||
"--event-time-start", | ||
event_time_start, | ||
"--event-time-end", | ||
event_time_end, | ||
] | ||
) | ||
assert expect_pass | ||
except Exception as e: | ||
assert ( | ||
"Value for `--event-time-start` must be less than `--event-time-end`" | ||
in e.__str__() | ||
) | ||
assert not expect_pass | ||
|
||
|
||
class TestEventTimeStartCurrent_time: | ||
@pytest.mark.parametrize( | ||
"event_time_start,current_time,expect_pass", | ||
[ | ||
("2024-10-01", "2024-10-02", True), | ||
("2024-10-02", "2024-10-01", False), | ||
], | ||
) | ||
def test_option_combo(self, project, event_time_start, current_time, expect_pass): | ||
with freeze_time(datetime.fromisoformat(current_time)): | ||
try: | ||
run_dbt(["build", "--event-time-start", event_time_start]) | ||
assert expect_pass | ||
except Exception as e: | ||
assert "must be less than the current time" in e.__str__() | ||
assert not expect_pass |