Skip prune on source failure#490
Open
muratbulat wants to merge 4 commits intobb-Ricardo:developmentfrom
Open
Conversation
pin pycares to 4.0.0, newer versions are incompatible with aiodns 3.0.0
bb-Ricardo
added a commit
that referenced
this pull request
Jan 29, 2026
Owner
|
Hi @muratbulat, thank you for the pull request. This is a great addition. Wonder why I never thought of this issue before. I would add a change and make it the actual default. If a source is unable then set prune to false. I just pushed a commit to the development branch. Would this solve the issue? |
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.
Problem
When a source (for example vCenter) is temporarily unavailable due to network issues, authentication errors, or maintenance, netbox-sync may fail to initialize that source and receive an empty inventory.
If pruning is enabled, this can incorrectly mark a large number of existing objects (VMs, interfaces, IP addresses) as orphaned and prune them from NetBox, even though the source outage is temporary.
Solution
This pull request introduces a safety guard that skips the prune step when one or more enabled sources fail to initialize during a sync run.
Pruning is only executed when enabled sources are successfully initialized, preventing accidental mass orphaning or deletions caused by transient source failures.
Behavior
No change when all enabled sources initialize successfully; pruning works as before.
If any enabled source fails to initialize, the prune step is skipped for that run and a warning is logged.
Pruning resumes automatically on the next successful run.
Configuration
A new optional configuration flag is added under the [netbox] section:
skip_prune_on_source_failure = TrueWhen enabled, pruning is skipped if at least one enabled source fails initialization.
Rationale
This change is intentionally safety-first and conservative. It does not alter normal prune behavior during healthy runs and helps protect NetBox data integrity during temporary source outages.