Skip to content

feat: allow loose matching on primary values after checking for unique#108

Open
ltucker wants to merge 5 commits into
developfrom
loose_matching
Open

feat: allow loose matching on primary values after checking for unique#108
ltucker wants to merge 5 commits into
developfrom
loose_matching

Conversation

@ltucker
Copy link
Copy Markdown
Contributor

@ltucker ltucker commented May 21, 2025

This updates diodes matching procedure to consider looser matches when no unique match can be found. This attempts a match on the "primary value" for the type when known (often "name" but not always).

  • unique matches are considered first and always preferred
  • If nothing matches loosely either, the object is considered new
  • If more than one object loosely matches, an ambiguity error is raised (these matches are not constrained to be unique and so may be ambiguous depending on NetBox state)

Some caveats:

This can potentially have unintended consequences (though these are in some respect the requested/desired types of actions)

if a "scoped" object (eg an object with an associated tenant, vrf etc) is specified and loosely matches and "unscoped" (eg global) object, the global object may be modified and become scoped rather than creating a new scoped object.

if an "unscoped" object is specified and a scoped object loosely matches the scoped object may be modified instead of creating a new global object.

Comment thread netbox_diode_plugin/api/plugin_utils.py Fixed
ltucker and others added 2 commits May 21, 2025 11:19
…rough an exception

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread netbox_diode_plugin/api/plugin_utils.py Fixed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 21, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
3264 2901 89% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
netbox_diode_plugin/api/matcher.py 86% 🟢
netbox_diode_plugin/api/plugin_utils.py 83% 🟢
netbox_diode_plugin/tests/test_api_diff_and_apply.py 100% 🟢
TOTAL 89% 🟢

updated for commit: 73430a7 by action🐍

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@ltucker
Copy link
Copy Markdown
Contributor Author

ltucker commented May 21, 2025

this is missing a test of the ambiguity error I believe

@leoparente leoparente self-requested a review October 31, 2025 18:31
Copy link
Copy Markdown
Contributor

@jajeffries jajeffries left a comment

Choose a reason for hiding this comment

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

Looks good, apart from the test failures :)

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.

4 participants