Skip to content

Commit

Permalink
If --event-time-end is not specififed, ensure --event-time-start
Browse files Browse the repository at this point in the history
…is less than the current time
  • Loading branch information
QMalcolm committed Oct 3, 2024
1 parent 5dc16b9 commit ee994c1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
15 changes: 10 additions & 5 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from functools import update_wrapper
from pathlib import Path

Expand Down Expand Up @@ -744,14 +745,18 @@ def wrapper(*args, **kwargs):
ctx = args[0]
assert isinstance(ctx, click.Context)

if (
ctx.params.get("event_time_start") is not None
and ctx.params.get("event_time_end") is not None
):
if ctx.params.get("event_time_start") >= ctx.params.get("event_time_end"):
event_time_start = ctx.params.get("event_time_start")
if event_time_start is not None:
event_time_end = ctx.params.get("event_time_end")

if event_time_end is not None and event_time_start >= event_time_end:
raise DbtRuntimeError(
"Value for `--event-time-end` must be less than `--event-time-end`"
)
elif event_time_start >= datetime.now():
raise DbtRuntimeError(
"Value for `--event-time-start` must be less than the current time if `--event-time-end` is not specififed"
)

return func(*args, **kwargs)

Expand Down
24 changes: 24 additions & 0 deletions tests/functional/cli/test_option_interaction_validations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from datetime import datetime

import pytest
from freezegun import freeze_time

from dbt.tests.util import run_dbt

Expand Down Expand Up @@ -28,3 +31,24 @@ def test_option_combo(self, project, event_time_start, event_time_end, expect_pa
"Value for `--event-time-end` 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 (
"Value for `--event-time-start` must be less than the current time if `--event-time-end` is not specififed"
in e.__str__()
)
assert not expect_pass

0 comments on commit ee994c1

Please sign in to comment.