Skip to content

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

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

ltucker
Copy link
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.

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>
Copy link

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
Contributor Author

ltucker commented May 21, 2025

this is missing a test of the ambiguity error I believe

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.

2 participants