Summary
With the NetBox 4.3 floor now enforced (#132), three of the five version-compatibility flags can no longer be false on any supported server. The branches they guard, and core/compat.py in its entirety, are unreachable in production but still carried, threaded and tested.
Why this is more than dead code
Until #132 the test suite constructed NetBox at versions 3.5, 4.0 and 4.1 in 98 places, all below the documented minimum. Those runs made the dead branches look live: a test could pass while asserting behaviour that no supported deployment will ever execute. That is the same "green while the real path is broken" failure a mock-heavy test produces, at the scale of a compatibility layer.
#132 bumped those 98 sites to the oldest supported release, so the misleading coverage is gone. What remains is the code it was covering.
What is now constant
| flag |
introduced for |
at 4.3+ |
modules |
NetBox >= 3.2 |
always true |
new_filters |
NetBox >= 4.1 |
always true |
rack_types |
NetBox >= 4.1 |
always true |
m2m_front_ports |
NetBox >= 4.5 |
still varies |
module_bay_types |
NetBox >= 4.7 |
still varies |
m2m_front_ports and module_bay_types are genuine and must stay.
Scope
core/compat.py exists only to pick between the old and new filter key names:
return "device_type_id" if new_filters else "devicetype_id"
return "module_type_id" if new_filters else "moduletype_id"
The devicetype_id / moduletype_id side is unreachable at 4.3+. The module collapses to two constants, or disappears into its callers. Callers: core/component_cache.py (lines 316, 318, 482, 483) and core/update_failure_resolver.py (line 139).
new_filters is referenced 39 times across core/, and is threaded through the DeviceTypes, ComponentCache and NetBoxGraphQLClient constructors purely to reach those two branches.
self.modules and self.rack_types guard whether module types and rack types are processed at all: core/import_run.py lines 458, 676, 687, 741, and the summary plumbing at 44, 69, 70, 533, 758.
Suggested approach
- Delete
core/compat.py, inline device_type_id / module_type_id at the four call sites.
- Remove the
new_filters parameter from the three constructors and its 39 references.
- Remove the
modules and rack_types flags and the branches they guard, keeping the behaviour of the true side.
- Keep
m2m_front_ports and module_bay_types untouched.
Ordering
Do this after #132 merges. The 4.3 floor is what makes the removal safe; landing it first, or out of order, would drop support for servers the importer still accepts.
Not included
Whether to raise the floor further. NetBox 4.3 reached end of life upstream some time ago, and a higher floor would retire m2m_front_ports too, but that is a support-policy decision rather than a cleanup and belongs in its own discussion.
Summary
With the NetBox 4.3 floor now enforced (#132), three of the five version-compatibility flags can no longer be false on any supported server. The branches they guard, and
core/compat.pyin its entirety, are unreachable in production but still carried, threaded and tested.Why this is more than dead code
Until #132 the test suite constructed
NetBoxat versions 3.5, 4.0 and 4.1 in 98 places, all below the documented minimum. Those runs made the dead branches look live: a test could pass while asserting behaviour that no supported deployment will ever execute. That is the same "green while the real path is broken" failure a mock-heavy test produces, at the scale of a compatibility layer.#132 bumped those 98 sites to the oldest supported release, so the misleading coverage is gone. What remains is the code it was covering.
What is now constant
modulesnew_filtersrack_typesm2m_front_portsmodule_bay_typesm2m_front_portsandmodule_bay_typesare genuine and must stay.Scope
core/compat.pyexists only to pick between the old and new filter key names:The
devicetype_id/moduletype_idside is unreachable at 4.3+. The module collapses to two constants, or disappears into its callers. Callers:core/component_cache.py(lines 316, 318, 482, 483) andcore/update_failure_resolver.py(line 139).new_filtersis referenced 39 times acrosscore/, and is threaded through theDeviceTypes,ComponentCacheandNetBoxGraphQLClientconstructors purely to reach those two branches.self.modulesandself.rack_typesguard whether module types and rack types are processed at all:core/import_run.pylines 458, 676, 687, 741, and the summary plumbing at 44, 69, 70, 533, 758.Suggested approach
core/compat.py, inlinedevice_type_id/module_type_idat the four call sites.new_filtersparameter from the three constructors and its 39 references.modulesandrack_typesflags and the branches they guard, keeping the behaviour of the true side.m2m_front_portsandmodule_bay_typesuntouched.Ordering
Do this after #132 merges. The 4.3 floor is what makes the removal safe; landing it first, or out of order, would drop support for servers the importer still accepts.
Not included
Whether to raise the floor further. NetBox 4.3 reached end of life upstream some time ago, and a higher floor would retire
m2m_front_portstoo, but that is a support-policy decision rather than a cleanup and belongs in its own discussion.