Skip prune on source failure #490
Open
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.