Repository navigation
Conversation
`check_preconditions(self, state, host)` is called on a bare `cls()` instance, while the arguments the fact was asked about stay in `fact_kwargs`. A fact that takes parameters therefore cannot use it: it has no way to tell which project, host or pool it is being asked about, which is what a precondition needs in order to check anything. The arguments now go with the call, named as the fact's `command` declares them. `self` is dropped first — `getcallargs` collects it alongside them, and `_make_command` drops it the same way before calling `command`. The signature ends in `*args, **kwargs`, as `requires_command`'s does, so an implementation may declare only what it needs: `(self, state, host)` stays valid, which is what the one existing implementation already writes, and `(self, state, host, pool=None)` becomes possible for a fact that depends on its own parameters. Naming the arguments explicitly would have forced every implementation, present and future, to accept a parameter it ignores. Worth having because the case it serves is a common one: a fact that reads a resource an earlier operation of the same deploy creates — a project, a pool, a namespace. pyinfra gathers facts before it runs any operation, so at that point the resource is not there yet; the fact's command fails, `state.fail_hosts()` drops the host, and the deploy is over before it ran anything. Silencing that during the prepare phase is exactly what `check_preconditions` is for, and it was out of reach for a fact with a parameter.
maisim
force-pushed
the
feat/check-preconditions-kwargs
branch
from
October 3, 2026 14:34
385fd0b to
eec3b9d
Compare
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.
check_preconditions(self, state, host)is called on a barecls()instance, while the arguments the fact was asked about stay infact_kwargs. A fact that takes parameters therefore cannot use it: it has no way to tell which project, host or pool it is being asked about, which is what a precondition needs in order to check anything.The arguments now go with the call, named as the fact's
commanddeclares them.selfis dropped first —getcallargscollects it alongside them, and_make_commanddrops it the same way before callingcommand.Nothing changes for a fact whose
commandtakes no parameters: it is called with no keyword arguments, which is whatZfsPools' implementation already expects.Worth having because the case it serves is a common one: a fact that reads a resource an earlier operation of the same deploy creates — a project, a pool, a namespace. pyinfra gathers facts before it runs any operation, so at that point the resource is not there yet; the fact's command fails,
state.fail_hosts()drops the host, and the deploy is over before it ran anything. Silencing that during the prepare phase is exactly whatcheck_preconditionsis for, and it was out of reach for a fact with a parameter.3.xat this time)scripts/dev-test.sh)scripts/dev-lint.sh)conventional commits format