Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions hamilton/function_modifiers/delayed.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ def optional_config(self) -> dict[str, Any] | None:
return self._optional_config

def resolve(self, config: dict[str, Any], fn: Callable) -> NodeTransformLifecycle:
if not config[settings.ENABLE_POWER_USER_MODE]:
if not config.get(settings.ENABLE_POWER_USER_MODE, False):
raise InvalidDecoratorException(
"Dynamic functions are only allowed in power user mode!"
"Dynamic functions are only allowed in power user mode. "
"Why? This is occasionally needed to enable highly flexible "
"dataflows, but it can compromise readability if you're not "
"careful! To enable power user mode, pass in the configuration "
f"parameter {settings.ENABLE_POWER_USER_MODE}=True to your driver."
"careful! To enable power user mode, build your driver with "
f".with_config({{{settings.ENABLE_POWER_USER_MODE!r}: True}})."
)
missing_configs = []
for item in self.required_config():
Expand Down
21 changes: 20 additions & 1 deletion tests/function_modifiers/test_delayed.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,30 @@ def fn() -> pd.DataFrame:
extract_columns(*cols_to_extract + some_cols_you_might_want_to_extract)
),
)
with pytest.raises(base.InvalidDecoratorException):
with pytest.raises(base.InvalidDecoratorException) as exc_info:
decorator.resolve(
{"cols_to_extract": ["a", "b"], **CONFIG_WITH_POWER_MODE_DISABLED},
fn=fn,
)
error_message = str(exc_info.value)
assert "power user mode" in error_message
assert ".with_config({'hamilton.enable_power_user_mode': True})" in error_message


def test_delayed_without_power_mode_config_fails_with_helpful_error():
def fn() -> pd.DataFrame:
return pd.DataFrame()

decorator = resolve(
when=ResolveAt.CONFIG_AVAILABLE,
decorate_with=lambda cols_to_extract: extract_columns(*cols_to_extract),
)

with pytest.raises(base.InvalidDecoratorException) as exc_info:
decorator.resolve({"cols_to_extract": ["a", "b"]}, fn=fn)
error_message = str(exc_info.value)
assert "power user mode" in error_message
assert ".with_config({'hamilton.enable_power_user_mode': True})" in error_message


def test_dynamic_resolve_with_extract_fields():
Expand Down