Skip to content

Commit 708fd8b

Browse files
committed
fix: allow subclassing of config again
1 parent 2adc37a commit 708fd8b

1 file changed

Lines changed: 5 additions & 32 deletions

File tree

sqlmesh/core/config/root.py

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class Config(BaseConfig):
121121
after_all: SQL statements or macros to be executed at the end of the `sqlmesh plan` and `sqlmesh run` commands.
122122
"""
123123

124-
gateways: t.Dict[str, GatewayConfig] = {"": GatewayConfig()}
124+
gateways: GatewayDict = {"": GatewayConfig()}
125125
default_connection: SerializableConnectionConfig = DuckDBConnectionConfig()
126126
default_test_connection_: t.Optional[SerializableConnectionConfig] = Field(
127127
default=None, alias="default_test_connection"
@@ -130,8 +130,8 @@ class Config(BaseConfig):
130130
default_gateway: str = ""
131131
notification_targets: t.List[NotificationTarget] = []
132132
project: str = ""
133-
snapshot_ttl: str = c.DEFAULT_SNAPSHOT_TTL
134-
environment_ttl: t.Optional[str] = c.DEFAULT_ENVIRONMENT_TTL
133+
snapshot_ttl: NoPastTTLString = c.DEFAULT_SNAPSHOT_TTL
134+
environment_ttl: t.Optional[NoPastTTLString] = c.DEFAULT_ENVIRONMENT_TTL
135135
ignore_patterns: t.List[str] = c.IGNORE_PATTERNS
136136
time_column_format: str = c.DEFAULT_TIME_COLUMN_FORMAT
137137
users: t.List[User] = []
@@ -141,12 +141,12 @@ class Config(BaseConfig):
141141
loader_kwargs: t.Dict[str, t.Any] = {}
142142
env_vars: t.Dict[str, str] = {}
143143
username: str = ""
144-
physical_schema_mapping: t.Dict[re.Pattern, str] = {}
144+
physical_schema_mapping: RegexKeyDict = {}
145145
environment_suffix_target: EnvironmentSuffixTarget = Field(
146146
default=EnvironmentSuffixTarget.default
147147
)
148148
gateway_managed_virtual_layer: bool = False
149-
environment_catalog_mapping: t.Dict[re.Pattern, str] = {}
149+
environment_catalog_mapping: RegexKeyDict = {}
150150
default_target_environment: str = c.PROD
151151
log_limit: int = c.DEFAULT_LOG_LIMIT
152152
cicd_bot: t.Optional[CICDBotConfig] = None
@@ -187,33 +187,6 @@ class Config(BaseConfig):
187187
_scheduler_config_validator = scheduler_config_validator # type: ignore
188188
_variables_validator = variables_validator
189189

190-
@field_validator("gateways", mode="before")
191-
@classmethod
192-
def _gateways_ensure_dict(cls, value: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
193-
try:
194-
if not isinstance(value, GatewayConfig):
195-
GatewayConfig.parse_obj(value)
196-
return {"": value}
197-
except Exception:
198-
return value
199-
200-
@field_validator("environment_catalog_mapping", "physical_schema_mapping", mode="before")
201-
@classmethod
202-
def _validate_regex_keys(
203-
cls, value: t.Dict[str | re.Pattern, t.Any]
204-
) -> t.Dict[re.Pattern, t.Any]:
205-
return compile_regex_mapping(value)
206-
207-
@field_validator("snapshot_ttl", "environment_ttl", mode="before")
208-
@classmethod
209-
def validate_no_past_ttl(cls, v: str) -> str:
210-
current_time = now()
211-
if to_timestamp(v, relative_base=current_time) < to_timestamp(current_time):
212-
raise ValueError(
213-
f"TTL '{v}' is in the past. Please specify a relative time in the future. Ex: `in 1 week` instead of `1 week`."
214-
)
215-
return v
216-
217190
@model_validator(mode="before")
218191
def _normalize_and_validate_fields(cls, data: t.Any) -> t.Any:
219192
if not isinstance(data, dict):

0 commit comments

Comments
 (0)