Skip to content

fix(ingester): don't clear a cluster's scope oneof when building a VirtualMachine - #111

Merged
ldrozdz93 merged 1 commit into
developfrom
obs-3803-cluster-scope-oneof-guard
Sep 11, 2026
Merged

ldrozdz93 merged 1 commit into
developfrom
obs-3803-cluster-scope-oneof-guard

Conversation

@ldrozdz93

Copy link
Copy Markdown
Contributor

Problem

VirtualMachine(cluster=…, site=…) writes scope_site into the caller's Cluster message. Cluster.scope is a protobuf oneof, so that write silently deletes whatever scope the caller had already set — a SiteGroup, Location or Region.

cluster = Cluster(name="c1", scope_site_group=SiteGroup(name="sg-1"))
VirtualMachine(name="vm-1", cluster=cluster, site=Site(name="site-1"))

cluster.WhichOneof("scope")   # "scope_site" — the SiteGroup is gone

The guard was not cluster.HasField("scope_site"), which is False while a sibling of the oneof holds the scope, so the write went ahead and CopyFrom cleared the sibling.

Fix

ingester.py is generated code. This is the artifact regenerated from netboxlabs/eng-observability-skunkworks#57, which taught the generator to guard a shortcut target belonging to a oneof with WhichOneof(<oneof>) instead of HasField(<field>). Over the current NetBox v4.7.0 generation that is a single line:

-            if cluster is not None and not cluster.HasField("scope_site"):
+            if cluster is not None and not cluster.WhichOneof("scope"):
                 cluster.scope_site.CopyFrom(site)

WhichOneof subsumes the old check, so an unscoped cluster is still filled from the VM's site and an already-scoped one is left alone. The other 19 shortcut writes target fields outside a oneof and are unchanged.

Adds a regression test for the case that was failing.

Closes OBS-3803.

🤖 Generated with Claude Code

…rtualMachine

VirtualMachine(cluster=..., site=...) filled the cluster's scope_site whenever
HasField("scope_site") was False. Cluster.scope is a oneof, so that guard is
also False when the caller already scoped the cluster to a SiteGroup, Location
or Region, and CopyFrom then silently cleared it.

ingester.py is regenerated output: this is the artifact produced by the
generator fix in netboxlabs/eng-observability-skunkworks#57, whose only change
over the current NetBox v4.7.0 generation is that guard.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
/opt/hostedtoolcache/Python/3.10.21/x64/lib/python3.10/site-packages/netboxlabs/diode/sdk
   chunking.py33197%112
   client.py5674293%202–203, 222–224, 227–230, 522, 590, 595, 599, 682–687, 732–734, 764, 768, 772, 794, 815, 817, 891, 922, 930, 992–993, 1002, 1035, 1062, 1067–1068, 1097, 1102–1105
   exceptions.py44393%69, 82–83
TOTAL6594693% 

Tests Skipped Failures Errors Time
214 0 💤 0 ❌ 0 🔥 1.963s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The fix is narrowly scoped and includes regression coverage for the affected behavior.

Pull request overview

Fixes VM cluster shortcut handling to preserve existing cluster scope oneof values.

Changes:

  • Uses WhichOneof("scope") before populating scope_site.
  • Adds regression coverage for existing SiteGroup scope.
File summaries
File Summary
tests/test_ingester.py Verifies existing cluster scope is preserved.
netboxlabs/diode/sdk/ingester.py Applies the oneof-aware guard.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ldrozdz93
ldrozdz93 merged commit 0925888 into develop Sep 11, 2026
9 checks passed
@ldrozdz93
ldrozdz93 deleted the obs-3803-cluster-scope-oneof-guard branch September 11, 2026 11:18
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.14.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants