Skip to content

feat: validation function for run() and run_async() parameters signature for (custom) components #9322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

davidsbatista
Copy link
Contributor

Related Issues

Proposed Changes:

Component signature validation mismatches between run and run_async method signatures, this is bound to happen with custom components as all haystack core and integration components by design don't have this issue.

  • new function _compare_method_signatures that provides detailed information about signature mismatches about:
    • Parameter count differences
    • Parameter name mismatches
    • Type annotation mismatches
    • Default value mismatches
    • Parameter kind mismatches (positional vs keyword)

How did you test it?

  • new test file test_component_signature_validation.py with comprehensive test cases cover all possible signature mismatch scenarios described above

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes
  • I added unit tests and updated the docstrings
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I documented my code
  • I ran pre-commit hooks and fixed any issue

@davidsbatista davidsbatista changed the title feat: validation function for run() and run_async() parameters signature for (custom) components feat: validation function for run() and run_async() parameters signature for (custom) components Apr 29, 2025
@coveralls
Copy link
Collaborator

coveralls commented Apr 29, 2025

Pull Request Test Coverage Report for Build 14732755474

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.01%) to 90.513%

Files with Coverage Reduction New Missed Lines %
core/component/component.py 1 99.44%
Totals Coverage Status
Change from base Build 14709162118: 0.01%
Covered Lines: 10896
Relevant Lines: 12038

💛 - Coveralls

@davidsbatista davidsbatista marked this pull request as ready for review April 29, 2025 11:57
@davidsbatista davidsbatista requested review from a team as code owners April 29, 2025 11:57
@davidsbatista davidsbatista requested review from dfokina and anakin87 and removed request for a team April 29, 2025 11:57
Copy link
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left two minor comments, but looks good to me!



def test_different_param_names():
with pytest.raises(ComponentError) as exc_info:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could use something like with pytest.raises(ComponentError, match="name mismatch")
in all tests if you want...

https://docs.pytest.org/en/stable/how-to/assert.html#matching-exception-messages

@@ -326,6 +329,48 @@ def _component_run_has_kwargs(component_cls: Type) -> bool:
)


def _compare_method_signatures(run_sig: inspect.Signature, async_run_sig: inspect.Signature) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _compare_method_signatures(run_sig: inspect.Signature, async_run_sig: inspect.Signature) -> str:
def _compare_run_methods_signatures(run_sig: inspect.Signature, async_run_sig: inspect.Signature) -> str:

nit: maybe this could be a clearer name

@davidsbatista davidsbatista enabled auto-merge (squash) April 29, 2025 13:42
@davidsbatista davidsbatista merged commit d61f9f7 into main Apr 29, 2025
20 checks passed
@davidsbatista davidsbatista deleted the detailed-message-show-difference-async-and-sync-args branch April 29, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validation for matching parameters on run and run_async should report which parameters don't match
3 participants