Skip to content

Commit 0b80e13

Browse files
Korijnbenc-db
andauthored
fix: Dynamically choose pydantic config field name to resolve deprecation warning (#1194)
Resolves #1047 ### Description The diff speaks for itself, choose the appropriate pydantic model config field based on the version of pydantic in the environment. This avoids the deprecation warning: ``` <my_repo>\env\Lib\site-packages\pydantic\_internal\_config.py:373: UserWarning: Valid config keys have changed in V2: * 'allow_population_by_field_name' has been renamed to 'validate_by_name' warnings.warn(message, UserWarning) ``` ### Checklist - [X] I have run this code in development and it appears to resolve the stated issue - [x] I have updated the `CHANGELOG.md` and added information about my change to the "dbt-databricks next" section. --------- Signed-off-by: Korijn van Golen <[email protected]> Co-authored-by: Ben Cassell <[email protected]>
1 parent 87073fe commit 0b80e13

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Fixes
44

55
- Fix issue causing MV/STs to always trigger as having their config changed ([1181](http://github.com/databricks/dbt-databricks/pull/1181))
6+
- Fix pydantic v2 deprecation warning "Valid config keys have changed in V2" (thanks @Korijn!) ([1194](https://github.com/databricks/dbt-databricks/pull/1194))
67

78
## dbt-databricks 1.10.12 (September 8, 2025)
89

dbt/adapters/databricks/python_models/python_config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from pydantic import BaseModel, Field, validator
55

6+
from .util import PYDANTIC_IS_V1
7+
68
DEFAULT_TIMEOUT = 60 * 60 * 24
79

810
JOB_PERMISSIONS = {"CAN_VIEW", "CAN_MANAGE_RUN", "CAN_MANAGE"}
@@ -84,4 +86,7 @@ def run_name(self) -> str:
8486
return f"{self.catalog}-{self.schema_}-{self.identifier}-{uuid.uuid4()}"
8587

8688
class Config:
87-
allow_population_by_field_name = True
89+
if PYDANTIC_IS_V1:
90+
allow_population_by_field_name = True
91+
else:
92+
populate_by_name = True
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from importlib.metadata import version
2+
3+
4+
def is_pydantic_v1() -> bool:
5+
"""Check if the installed version of pydantic is v1."""
6+
try:
7+
pydantic_version = version("pydantic")
8+
major = int(pydantic_version.split(".")[0])
9+
return major < 2
10+
except Exception:
11+
# If we can't determine the version, assume v1 for compatibility
12+
# See: https://github.com/databricks/dbt-databricks/pull/976#issuecomment-2748680090
13+
return True
14+
15+
16+
PYDANTIC_IS_V1 = is_pydantic_v1()

0 commit comments

Comments
 (0)