From 7b995c553a1702fa934a6522788fc1728aa7677d Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Mon, 7 Oct 2024 13:14:30 -0500 Subject: [PATCH] Move logic to validate `event_time` cli flags to `flags.py` --- core/dbt/cli/flags.py | 22 ++++++++++++++++++++++ core/dbt/cli/main.py | 2 -- core/dbt/cli/params.py | 26 -------------------------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/core/dbt/cli/flags.py b/core/dbt/cli/flags.py index d3dabded7b0..f55b99ffbb5 100644 --- a/core/dbt/cli/flags.py +++ b/core/dbt/cli/flags.py @@ -1,6 +1,7 @@ import os import sys from dataclasses import dataclass +from datetime import datetime from importlib import import_module from pathlib import Path from pprint import pformat as pf @@ -313,6 +314,9 @@ def _assign_params( self._assert_mutually_exclusive(params_assigned_from_default, ["SELECT", "INLINE"]) self._assert_mutually_exclusive(params_assigned_from_default, ["SELECTOR", "INLINE"]) + # Check event_time configs for validity + self._validate_event_time_configs() + # Support lower cased access for legacy code. params = set( x for x in dir(self) if not callable(getattr(self, x)) and not x.startswith("__") @@ -349,6 +353,24 @@ def _assert_mutually_exclusive( elif flag_set_by_user: set_flag = flag + def _validate_event_time_configs(self) -> None: + event_time_start = ( + getattr(self, "EVENT_TIME_START") if hasattr(self, "EVENT_TIME_START") else None + ) + if event_time_start is not None: + event_time_end = ( + getattr(self, "EVENT_TIME_END") if hasattr(self, "EVENT_TIME_END") else None + ) + + if event_time_end is not None and event_time_start >= event_time_end: + raise DbtUsageException( + "Value for `--event-time-start` must be less than `--event-time-end`" + ) + elif event_time_start >= datetime.now(): + raise DbtUsageException( + "Value for `--event-time-start` must be less than the current time if `--event-time-end` is not specififed" + ) + def fire_deprecations(self): """Fires events for deprecated env_var usage.""" [dep_fn() for dep_fn in self.deprecated_env_var_warnings] diff --git a/core/dbt/cli/main.py b/core/dbt/cli/main.py index ebc7bdd73f1..610163042c4 100644 --- a/core/dbt/cli/main.py +++ b/core/dbt/cli/main.py @@ -187,7 +187,6 @@ def cli(ctx, **kwargs): @p.vars @requires.postflight @requires.preflight -@p.validate_option_interactions @requires.profile @requires.project @requires.runtime_config @@ -562,7 +561,6 @@ def parse(ctx, **kwargs): @p.vars @requires.postflight @requires.preflight -@p.validate_option_interactions @requires.profile @requires.project @requires.runtime_config diff --git a/core/dbt/cli/params.py b/core/dbt/cli/params.py index ff46f7152cf..96e9e7acd7a 100644 --- a/core/dbt/cli/params.py +++ b/core/dbt/cli/params.py @@ -1,5 +1,3 @@ -from datetime import datetime -from functools import update_wrapper from pathlib import Path import click @@ -7,7 +5,6 @@ from dbt.cli.option_types import YAML, ChoiceTuple, Package, WarnErrorOptionsType from dbt.cli.options import MultiOption from dbt.cli.resolvers import default_profiles_dir, default_project_dir -from dbt.exceptions import DbtRuntimeError from dbt.version import get_version_information add_package = click.option( @@ -738,26 +735,3 @@ def _version_callback(ctx, _param, value): envvar="DBT_SHOW_RESOURCE_REPORT", hidden=True, ) - - -def validate_option_interactions(func): - def wrapper(*args, **kwargs): - ctx = args[0] - assert isinstance(ctx, click.Context) - - 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-start` 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) - - return update_wrapper(wrapper, func)