fix(graphql): fall back to client-side vendor scoping when NetBox rejects template filters - #121
Conversation
…ects template filters NetBox 4.3.0 gave the GraphQL PowerOutletTemplateFilter the component mixin (device/device_id) instead of the template mixin (device_type/module_type), so vendor-scoped power_outlet_template_list queries are rejected by the schema on every released 4.3.x and 4.4.x. NetBox fixed the filter in netbox-community/netbox#20935, first shipped in v4.5.0, with no backport to 4.4.x. When a vendor-scoped component template query raises GraphQLSchemaError, get_component_templates now fetches the endpoint unfiltered once and scopes the records client-side against the vendor's device type and module type ids (string-normalized on both sides). Transport errors keep the existing retry and propagation behavior; only a schema rejection triggers the fallback, so the slow path cannot hide a flaky server. An asymmetric rejection (device leg accepted, module leg rejected) falls back for the module leg alone without fetching device type ids. Fixes #120
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthrough
ChangesVendor template fallback
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change adds a narrowly scoped fallback for rejected vendor filters while preserving transport-error behavior; no actionable merge-blocking risk remains after normal checks and review. Sequence Diagram(s)sequenceDiagram
participant get_component_templates
participant GraphQLEndpoint
participant ManufacturerTypeQueries
get_component_templates->>GraphQLEndpoint: Request vendor-filtered templates
GraphQLEndpoint-->>get_component_templates: Return GraphQLSchemaError
get_component_templates->>GraphQLEndpoint: Request unfiltered templates
get_component_templates->>ManufacturerTypeQueries: Fetch manufacturer parent types
ManufacturerTypeQueries-->>get_component_templates: Return parent IDs
get_component_templates-->>get_component_templates: Filter templates by parent IDs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #120.
Root cause
NetBox 4.3.0 gave the GraphQL
PowerOutletTemplateFilterthe wrong mixin:ModularComponentModelFilterMixin(the one for device-attached components, exposingdevice/device_id/module/module_id) instead ofModularComponentTemplateFilterMixin(exposingdevice_type/module_type). Every other component template filter has the correct template mixin. As a result, the vendor-scoped preload querypower_outlet_template_list(filters: {device_type: ...})is rejected by the schema on every released 4.3.x and 4.4.x, with the exact error from the issue. Only the filter input type is broken; the unfiltered query and thedevice_type { id }/module_type { id }selections work.NetBox fixed the mixin in netbox-community/netbox#20935, first shipped in v4.5.0. The 4.4.x line never received a backport (still broken in 4.4.10).
The importer only started tripping on this in v1.8.0, when the vendor-scoped GraphQL preload was introduced (#117). The weekly live integration lane tests against NetBox
main, which has carried the fix since December 2025, so no CI lane ever exercised a released 4.3/4.4 schema.Fix
get_component_templatescatchesGraphQLSchemaErroron a vendor-scoped component query (schema rejection only; transport errors keep the existing retry and propagation behavior) and falls back to one unfiltered fetch of that endpoint, scoping the records client-side against the vendor's device type and module type ids. Ids are string-normalized on both sides of the comparison. If only the module leg is rejected while the device leg succeeded, the fallback keeps module-parented records alone and skips the device-type id fetch. This mirrors the existing image-attachment schema fallback and self-heals on NetBox >= 4.5.Tests
Written red-first against the unfixed code, at the transport boundary (the client's real query construction and error classification run for real against a fake NetBox 4.4 responder):
Full suite: 1046 passed.
Summary by CodeRabbit
Bug Fixes
Tests