You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hamilton.apache.org by je...@apache.org on 2026/06/07 18:47:34 UTC
(hamilton) branch main updated: Improve power user mode error for dynamic resolvers (#1604)
This is an automated email from the ASF dual-hosted git repository.
jernejfrank pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hamilton.git
The following commit(s) were added to refs/heads/main by this push:
new 5f9cda08 Improve power user mode error for dynamic resolvers (#1604)
5f9cda08 is described below
commit 5f9cda08d00e5c7543c694acbbac04d12c89c0fe
Author: Asish Kumar <87...@users.noreply.github.com>
AuthorDate: Mon Jun 8 00:17:29 2026 +0530
Improve power user mode error for dynamic resolvers (#1604)
---
hamilton/function_modifiers/delayed.py | 8 ++++----
tests/function_modifiers/test_delayed.py | 21 ++++++++++++++++++++-
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/hamilton/function_modifiers/delayed.py b/hamilton/function_modifiers/delayed.py
index d1fa34b9..d88179dd 100644
--- a/hamilton/function_modifiers/delayed.py
+++ b/hamilton/function_modifiers/delayed.py
@@ -148,13 +148,13 @@ class resolve(DynamicResolver):
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():
diff --git a/tests/function_modifiers/test_delayed.py b/tests/function_modifiers/test_delayed.py
index b48fc92b..65da7554 100644
--- a/tests/function_modifiers/test_delayed.py
+++ b/tests/function_modifiers/test_delayed.py
@@ -167,11 +167,30 @@ def test_delayed_without_power_mode_fails():
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():