Skip to content

Commit a5fbf14

Browse files
pr feedback
1 parent 8ed8df4 commit a5fbf14

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

sqlmesh/dbt/builtin.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,23 @@ def __init__(self, config_dict: t.Dict[str, t.Any]) -> None:
171171
self._config = config_dict
172172

173173
def __call__(self, *args: t.Any, **kwargs: t.Any) -> str:
174-
if args and not kwargs and len(args) == 1 and isinstance(args[0], dict):
175-
# Single dict argument: config({"materialized": "table"})
176-
self._config.update(args[0])
177-
elif not args and kwargs:
178-
# Keyword arguments: config(materialized="table")
179-
self._config.update(kwargs)
180-
elif args:
174+
if args and kwargs:
181175
raise ConfigError(
182-
f"Invalid config usage: expected either a single dict or keyword arguments"
176+
"Invalid inline model config: cannot mix positional and keyword arguments"
183177
)
178+
179+
if args:
180+
if len(args) == 1 and isinstance(args[0], dict):
181+
# Single dict argument: config({"materialized": "table"})
182+
self._config.update(args[0])
183+
else:
184+
raise ConfigError(
185+
f"Invalid inline model config: expected a single dictionary, got {len(args)} arguments"
186+
)
187+
elif kwargs:
188+
# Keyword arguments: config(materialized="table")
189+
self._config.update(kwargs)
190+
184191
return ""
185192

186193
def set(self, name: str, value: t.Any) -> str:

tests/dbt/test_transformation.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,14 +1075,22 @@ def test_config_dict_syntax():
10751075
config3({"materialized": "table"}, alias="mixed")
10761076
assert False, "Should have raised ConfigError"
10771077
except Exception as e:
1078-
assert "Invalid config usage" in str(e)
1078+
assert "cannot mix positional and keyword arguments" in str(e)
10791079

10801080
# Test nested dicts
10811081
config4 = Config({})
10821082
config4({"meta": {"owner": "data_team", "priority": 1}, "tags": ["daily", "critical"]})
10831083
assert config4._config["meta"]["owner"] == "data_team"
10841084
assert config4._config["tags"] == ["daily", "critical"]
10851085

1086+
# Test multiple positional arguments are rejected
1087+
config4 = Config({})
1088+
try:
1089+
config4({"materialized": "table"}, {"alias": "test"})
1090+
assert False
1091+
except Exception as e:
1092+
assert "expected a single dictionary, got 2 arguments" in str(e)
1093+
10861094

10871095
def test_config_dict_in_jinja():
10881096
# Test dict syntax directly with Config class

0 commit comments

Comments
 (0)