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

Ensure that Fact#command does not take global arguments #1115

Merged
merged 2 commits into from
Jun 8, 2024

Conversation

martenlienen
Copy link
Contributor

A recent commit c89e211 changed getting facts so that arguments to FactBase#command clashing with global arguments are filtered from the kwargs. This includes the often used argument name and facts like DebPackage broke as a result.

This PR introduces a check that subclasses of FactBase don't take any global arguments in their command method and updates all existing facts and tests accordingly. There is also a tiny bit of improved shell quoting in the deb, pacman and rpm facts.

@Fizzadar
Copy link
Member

Fizzadar commented Jun 4, 2024

A recent commit c89e211 changed getting facts so that arguments to FactBase#command clashing with global arguments are filtered from the kwargs. This includes the often used argument name and facts like DebPackage broke as a result.

heh, guess we know why the old handling existed! Lack of comments on that meant I had long forgotten the context which makes sense! This approach is cleaner, and although the global name argument clash is annoying it makes sense to keep things consistent between facts and operations.

Not quite got time to review code right now but thank you for pulling this one together @martenlienen 🙏

Copy link
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

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

Thank you @martenlienen, this is great work. Also good to change this now ahead of 3.0 with the breaking arg change 🙏

# Check that fact's `command` method does not inadvertently take a global
# argument, most commonly `name`.
if hasattr(cls, "command") and callable(cls.command):
command_args = set(inspect.signature(cls.command).parameters.keys())
Copy link
Member

@Fizzadar Fizzadar Jun 8, 2024

Choose a reason for hiding this comment

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

This is neat, will copy this to operations as well!

@Fizzadar Fizzadar merged commit 004a0f4 into pyinfra-dev:3.x Jun 8, 2024
22 checks passed
@martenlienen martenlienen deleted the fact-name-arg branch June 9, 2024 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants