Repository navigation
Conversation
Under the sync Driver an AsyncDataValidator's wrapper node returns an unawaited coroutine, and the final validation node passed it to act_warn or act_fail_bulk, which failed with AttributeError on .passes. The final node now closes such a coroutine and raises the documented TypeError naming the validator and pointing to AsyncDriver. Closes apache#1759
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #1759
An
AsyncDataValidatorused with the synchronousDriverfailed withAttributeError: 'coroutine' object has no attribute 'passes'and a "coroutine was never awaited" warning, instead of theTypeErrorthe data quality docs describe. The async validator gets anasync defwrapper node, the sync driver stores its unawaited coroutine as the node result, andfinal_node_callablehanded that coroutine toact_warn/act_fail_bulk.Changes
hamilton/function_modifiers/validation.py: infinal_node_callable, if a validator node's result is a coroutine, close it and raiseTypeErrornaming the validator and saying to useAsyncDriver(same message as the existing guard in the sync wrapper). The async wrapper and theAsyncDriverpath are unchanged, since underAsyncDriverthe result is already awaited before it reaches the final node.How I tested this
test_sync_driver_with_async_validator_raises_type_errorintests/function_modifiers/test_validation.py, parametrized overimportance="warn"and"fail". It builds a syncDriverover a node decorated with@check_output_custom(AsyncSampleDataValidator(...)), assertsexecuteraisesTypeErrormentioningAsyncDriver, and asserts no "never awaited"RuntimeWarningis emitted. Both cases failed with theAttributeErrorbefore the change and pass after it.pytest tests/function_modifiers tests/plugins/test_polars*.py: everything that passed before still passes. The polars plugin tests that fail locally fail the same way without this change (polars 2.0 removed arguments they use, andxlsxwriteris not installed).ruff checkandruff format --checkon the changed files are clean.Notes
If a node has several async validators, only the first coroutine is closed before the error is raised; the others can still produce a "never awaited" warning when collected. The error raised is the same either way.
Checklist