Skip to content
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

User report Hook with keyword argument does not work #4098

Open
noklam opened this issue Aug 15, 2024 · 2 comments
Open

User report Hook with keyword argument does not work #4098

noklam opened this issue Aug 15, 2024 · 2 comments
Assignees
Labels
Community Issue/PR opened by the open-source community Component: Documentation 📄 Issue/PR for markdown and API documentation

Comments

@noklam
Copy link
Contributor

noklam commented Aug 15, 2024

Description

An user struggle with using before_pipeline_run hook, upon investigation I think the root cause is in pluggy.
Slack archive: https://linen-slack.kedro.org/t/22922543/hi-all-i-have-a-profiling-hook-that-uses-the-before-pipeline#42b185d3-2eca-445b-80f7-514b35bd6d12

class DummyHooks:
    @hook_impl
    def before_pipeline_run(self, run_params: Dict[str, Any] = dict()):
        print(run_params)

The user use the above hook and find run_params result in {}, this has nothing to do with the default value. If we change run_params=123, the hook will print 123 instead. In pluggy documentation it never use keyword arguments, but also didn't explicitly said this is not allowed.

I checked the implementation and don't immediate understand why keywords is not possible, so it could be either a bug or intentional. I follow up in this issue:
Github: pytest-dev/pluggy#522

@noklam noklam self-assigned this Aug 15, 2024
@noklam noklam added the Community Issue/PR opened by the open-source community label Aug 15, 2024
@noklam
Copy link
Contributor Author

noklam commented Aug 15, 2024

I put this as a community ticket as there is no immediate action we can do. If pluggy confirm this is expected, maybe we can add some documents on our side to make this obvious.

@astrojuanlu
Copy link
Member

(If I may add something, don't use mutable objects as default values for function arguments!)

Unlikely that this behavior will change upstream pytest-dev/pluggy#15

If anything, I think we should trat this a documentation issue on our side (to compensate for the fact that this isn't mentioned in the pluggy docs, as far as I can see? https://pluggy.readthedocs.io/en/stable/)

@astrojuanlu astrojuanlu added the Component: Documentation 📄 Issue/PR for markdown and API documentation label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Issue/PR opened by the open-source community Component: Documentation 📄 Issue/PR for markdown and API documentation
Projects
Status: No status
Development

No branches or pull requests

2 participants