Skip to content

fix: limit-aware inventory creation#1757

Open
etiennecollin wants to merge 1 commit into
pyinfra-dev:3.xfrom
etiennecollin:etiennecollin/limit-aware-inventory-creation
Open

fix: limit-aware inventory creation#1757
etiennecollin wants to merge 1 commit into
pyinfra-dev:3.xfrom
etiennecollin:etiennecollin/limit-aware-inventory-creation

Conversation

@etiennecollin
Copy link
Copy Markdown

@etiennecollin etiennecollin commented May 16, 2026

Description

This draft PR is a proof of concept for #1756.

The current issue is that --limit <group> still allows host data from non-selected groups to be merged during inventory construction. If the same host exists in multiple groups with overlapping keys, values from later groups overwrite those from the selected group.

This implementation explores passing the limit iterable into the Inventory object so that host data from non-selected groups can be ignored during inventory construction.

The goal here is mainly to validate the approach; I do not expect this implementation to be merged as-is, since it was written fairly quickly and may not align with the intended architecture of the project. It may serve as inspiration for a proper implementation.

Testing

The included tests pass with scripts/dev-test.sh, but I encountered the following error in one of my real deployments, which does not occur on pyinfra v3.8.0. So there is likely at least one edge case or unintended side effect in the current implementation. The error also happens on 3.8.0, so it might be my deployment that is flawed.

--> pyinfra error: Cycle detected in operation ordering DAG.
    Error: ('nodes are in a cycle', ['6122ecd5c8bf5453cf3cefd3b6786f892d5d01af', 'af7a299a1fa7001b19dc57f7f9a1249385411c40-0', 'b2c4a8bab430d883f638396faaf8251b721a058d-0', '0ae435d43f8108d80868fdf5c2a700ed581f139f-0', 'eccb013008ef20c412778a9b62f4dfbf3d7013f2-0', 'accace0f63f34b5b36b28d67ad44597a71d21803', '6122ecd5c8bf5453cf3cefd3b6786f892d5d01af'])

    This can happen when using loops in operation code, please see: https://docs.pyinfra.com/en/latest/deploy-process.html#loops-cycle-errors

Checklist

  • Pull request is based on the default branch (3.x at this time)
  • Pull request includes tests for any new/updated operations/facts
  • Pull request includes documentation for any new/updated operations/facts
  • Tests pass (see scripts/dev-test.sh)
  • Type checking & code style passes (see scripts/dev-lint.sh)
  • Pull request title follows the conventional commits format

@wowi42 wowi42 added API API mode specific issues. CLI CLI mode specific issues. bug Label for all kind of bugs. labels May 16, 2026
@etiennecollin etiennecollin marked this pull request as ready for review May 17, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API API mode specific issues. bug Label for all kind of bugs. CLI CLI mode specific issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants