Skip to content

Conversation

@nickhilliard
Copy link

What does this PR do?

The netbox API changed format in netbox 4.2.0 to change to a generic foreign key format. This commit allows both old and new API formats.

What issues does this PR fix or reference?

Fixes #68375

Previous Behavior

the minion pillar data failed to load with:

2025-11-10 17:33:48,613 [salt.pillar      :1228][ERROR   ][3692613] Exception caught loading ext_pillar 'netbox':
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/__init__.py", line 1220, in ext_pillar
    ext = self._external_pillar_data(pillar, val, key)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/__init__.py", line 1140, in _external_pillar_data
    ext = self.ext_pillars[key](self.minion_id, pillar, **val)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 162, in __call__
    ret = self.loader.run(run_func, *args, **kwargs)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1248, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1263, in _run_as
    ret = _func_or_method(*args, **kwargs)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/netbox.py", line 1157, in ext_pillar
    ret["netbox"]["site"]["prefixes"] = _get_site_prefixes(
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/netbox.py", line 1023, in _get_site_prefixes
    del site_prefixes_results[prefix_count]["site"]

New Behavior

minion pillar now loads

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

No

@nickhilliard nickhilliard requested a review from a team as a code owner November 10, 2025 18:35
@welcome
Copy link

welcome bot commented Nov 10, 2025

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here's some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at [email protected]. We're glad you've joined our community and look forward to doing awesome things with you!

CHANGELOG.md Outdated
Comment on lines 10 to 15
## [Unreleased]

### Fixed

- Fixed issue with upstream Netbox API changing api/ipam/prefixes output to
use "scope" FK instead of "site" [#68375](https://github.com/saltstack/salt/issues/68375)
Copy link
Contributor

@bdrx312 bdrx312 Nov 10, 2025

Choose a reason for hiding this comment

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

This file is not edited manually to add change logs. See https://docs.saltproject.io/en/master/topics/development/contributing.html#changelog-and-commit for steps on adding a change log

Copy link
Author

Choose a reason for hiding this comment

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

noted + changed.

prefix_count = 0
for prefix in site_prefixes_results:
del site_prefixes_results[prefix_count]["site"]
if "site" in site_prefixes_results[prefix_count].keys():
Copy link
Contributor

@bdrx312 bdrx312 Nov 10, 2025

Choose a reason for hiding this comment

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

For checking if an item is in a dictionary you just call in against the dictionary reference itself--you don't call in on .keys(): if "site" in site_prefixes_results[prefix_count]:. However you may just want to try to delete both:

site_prefixes_results[prefix_count].pop("site", None)
site_prefixes_results[prefix_count].pop("scope", None)

Copy link
Author

Choose a reason for hiding this comment

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

noted + changed.

@twangboy
Copy link
Contributor

Netbox has been removed from salt starting with the 3008 release. It is recommended that all bug fixes go into the netbox salt extension.
https://github.com/salt-extensions/saltext-netbox

@nickhilliard nickhilliard force-pushed the bf-netbox-api-ipam-prefixes branch from 796da2d to 7f07a7b Compare November 11, 2025 19:11
@nickhilliard
Copy link
Author

Netbox has been removed from salt starting with the 3008 release. It is recommended that all bug fixes go into the netbox salt extension. https://github.com/salt-extensions/saltext-netbox

yes, it's was removed in commit dc526dc, i.e. already not present in 3007.x. This commit is against 3006.x.

There's nothing in the saltext-netbox repo yet. If/when it appears there, I'll make sure it's ported over there.

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.

3 participants