Skip to content

Commit 0c2ba86

Browse files
authored
Fix: Support aliases for the password field in dbt target config (#5167)
1 parent cce46b5 commit 0c2ba86

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

sqlmesh/dbt/target.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pathlib import Path
66

77
from dbt.adapters.base import BaseRelation, Column
8-
from pydantic import Field
8+
from pydantic import Field, AliasChoices
99

1010
from sqlmesh.core.console import get_console
1111
from sqlmesh.core.config.connection import (
@@ -329,7 +329,7 @@ class PostgresConfig(TargetConfig):
329329
type: t.Literal["postgres"] = "postgres"
330330
host: str
331331
user: str
332-
password: str
332+
password: str = Field(validation_alias=AliasChoices("pass", "password"))
333333
port: int
334334
dbname: str
335335
keepalives_idle: t.Optional[int] = None
@@ -417,7 +417,7 @@ class RedshiftConfig(TargetConfig):
417417
type: t.Literal["redshift"] = "redshift"
418418
host: str
419419
user: str
420-
password: str
420+
password: str = Field(validation_alias=AliasChoices("pass", "password"))
421421
port: int
422422
dbname: str
423423
connect_timeout: t.Optional[int] = None

tests/dbt/test_config.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,28 @@ def test_postgres_config():
650650
"outputs",
651651
"dev",
652652
)
653+
# 'pass' field instead of 'password'
654+
_test_warehouse_config(
655+
"""
656+
dbt-postgres:
657+
target: dev
658+
outputs:
659+
dev:
660+
type: postgres
661+
host: postgres
662+
user: postgres
663+
pass: postgres
664+
port: 5432
665+
dbname: postgres
666+
schema: demo
667+
threads: 3
668+
keepalives_idle: 0
669+
""",
670+
PostgresConfig,
671+
"dbt-postgres",
672+
"outputs",
673+
"dev",
674+
)
653675

654676

655677
def test_redshift_config():
@@ -674,6 +696,28 @@ def test_redshift_config():
674696
"outputs",
675697
"dev",
676698
)
699+
# 'pass' field instead of 'password'
700+
_test_warehouse_config(
701+
"""
702+
dbt-redshift:
703+
target: dev
704+
outputs:
705+
dev:
706+
type: redshift
707+
host: hostname.region.redshift.amazonaws.com
708+
user: username
709+
pass: password1
710+
port: 5439
711+
dbname: analytics
712+
schema: analytics
713+
threads: 4
714+
ra3_node: false
715+
""",
716+
RedshiftConfig,
717+
"dbt-redshift",
718+
"outputs",
719+
"dev",
720+
)
677721

678722

679723
def test_databricks_config():

0 commit comments

Comments
 (0)