Add baker_recipes.py files for circuits, dcim, tenancy, and ipam apps
with Recipe objects that document model relationships and provide named
status variants (active_circuit, planned_circuit, offline_circuit).
Convert CircuitTestCase in test_filtersets.py to use recipes instead of
bare baker.make() calls. All 127 filterset tests pass.
This commit sits alongside the existing baker.make() conversion so
reviewers can compare both approaches.
- Add model-bakery to base_requirements.txt and requirements.txt
- Add comment explaining MPTT_ALLOW_TESTING_GENERATORS setting
- Convert remaining bulk_create calls to baker.make in filtersets
- Replace fragile .objects.first() refs with stored class attributes
in JSON import tests
Replace manual object creation in all circuits test files with
model_bakery's baker.make() calls. This reduces test setup boilerplate
by ~500 lines while maintaining identical test coverage (708 tests).
Add MPTT_ALLOW_TESTING_GENERATORS setting to allow model_bakery to
create objects with MPTT foreign key chains in the test environment.
The new "select at least one field" guard fires when rename_fields is set
and no field_names are submitted. Add field_names=['name'] to both the
preview and apply POST data so the test exercises the intended rename path.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The `submitted` list comprehension previously called `f in self.rename_fields`
which raises TypeError when a subclass sets rename_fields=None. Short-circuit
with `self.rename_fields and` to safely handle None, empty tuple, and populated
tuples uniformly.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add form error when all field checkboxes are unchecked on submit;
previously fell back to renaming every declared field silently
- Remove obj.new_name backward-compat assignment; no template or
documented plugin API references it (all use obj.new_names now)
- Update base test data to include field_names=['name'] so the guard
does not fire in views-framework tests that don't specify fields
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Move field checkboxes before the find/replace/use_regex inputs so they
are not visually conflated with the 'use regex' checkbox
- Fix indentation inside the {% if rename_fields %} block
- Add trailing newline to bulk_rename.html
- Add test_bulk_rename_name_and_label_fields to verify that submitting
field_names=['name', 'label'] updates both fields simultaneously
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace the dynamic label-field detection (_get_rename_fields) and dropdown
with an explicit rename_fields class attribute and per-field checkboxes:
- BulkRenameView.rename_fields: tuple of field names (e.g. ('name', 'label'))
declared on the view. field_name is retained for backward compatibility
with plugins that set it directly.
- When rename_fields has 2+ entries, the template renders a Bootstrap-styled
checkbox per field (all checked by default) so users can apply the
find/replace to any combination of fields simultaneously. Checkboxes are
rendered directly in the template and read from request.POST rather than
through a form field, to avoid Django widget styling complications.
- _rename_objects accepts field_names (list) and stores per-field results in
obj.new_names (SimpleNamespace) + obj.has_changes for template use.
- The apply step iterates field_names and setattr for each selected field.
- bulk_rename.html: unified table iterates selected_field_names; form section
inline-expands render_form so the Fields checkboxes slot between the
standard fields and the changelog fieldset.
- Add rename_fields = ('name', 'label') to the 20 DCIM component/template
views whose models carry both name and label fields.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Trim _get_rename_fields docstring and required=False comment to single lines
- Pass field_name as a parameter to _rename_objects instead of extracting it
from form.cleaned_data inside the method (single source of truth)
- Fix test skip condition to use _meta.fields instead of _meta.get_fields()
to match the implementation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
For device/module component models, the preview table now always shows four
columns: Current Name, New Name, Current Label, New Label. The New column
for the non-targeted field is left empty to make clear which field the
find/replace pattern applies to. This gives users full context when
identifying objects and planning renames.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Use _meta.fields (concrete fields only) instead of _meta.get_fields()
to check for label field presence; avoids iterating reverse relations
- Simplify template column headers via blocktrans + field_name|title
instead of duplicated if/else blocks
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Device/module component models (Interface, ConsolePort, FrontPort, etc. and
their template counterparts) have both a 'name' and a 'label' field. The bulk
rename form now shows a 'Field' dropdown on these models so users can choose
which field to apply the find/replace pattern to; the selector is omitted for
models that have only one renameable field.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds warning and examples for validating NetBox objects before saving
in Custom Scripts. Direct ORM writes bypass UI/API validation and can
introduce invalid data. Recommends calling `full_clean()` explicitly.
Fixes#22249
Extract _NumericLookupMixin with shared get_filter() and filter() methods.
IntegerLookup, BigIntegerLookup, and FloatLookup each inherit from it and
declare only their type-specific fields, eliminating triplicated logic.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Require a Circuit Termination target when a termination type has been
selected, so blank dynamic target fields surface an inline form error
instead of falling through to generic GFK validation for termination_id.
Add a model-level guard for the same invalid state before generic
GenericForeignKey validation runs.
Fixes#22163
Fix miscounting of total_vlan_ids when VLANGroup vid_ranges use
non-canonical bounds (e.g. '[]'). Normalize ranges to '[)' on save and
add migration to recompute existing totals. Prevent division-by-zero in
utilization queries for legacy rows with miscounted totals.
Fixes#22228
Remove `@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])` decorators
across test suites, replacing them with explicit `add_permissions()`
calls for required view permissions. Improves test clarity and ensures
permission checks are properly validated.
Fixes#22091
Have TableConfigSerializer inherit from ChangeLogMessageSerializer so
changelog_message values submitted via the REST API are recorded on the
resulting ObjectChange.
This aligns table configs with other changelog-tracked extras models.
Fixes#22236
Add test ensuring each model-backed table has a corresponding test case
inheriting from StandardTableTestCase with correct table attribute set.
Includes helper method to import table test classes by model.
Fixes#22110
Adds the cable_id FK companion filter and 9 termination object filters
(consoleport_id, consoleserverport_id, powerport_id, poweroutlet_id,
interface_id, frontport_id, rearport_id, powerfeed_id,
circuittermination_id), mirroring the CableFilterSet pattern.
Adds a corresponding CableTerminationTestCase using ChangeLoggedFilterSetTests
so future missing-filter regressions are caught automatically.
Fixes#22209
Prevent TypeError when TableConfig.ordering is None by adding explicit
null check in clean(). Add regression test covering unset ordering
field.
Fixes#22206
Guard max(releases) against an empty iterable to prevent a ValueError
when the release-check endpoint returns only prereleases, dev releases,
or entries lacking a tag_name.
Fixes#22202
Add test suites for SystemHousekeepingJob, SyncDataSourceJob, and
ScriptJob covering housekeeping tasks, data source synchronization,
script rollback paths, and request processor integration.
Includes helpers to safely instantiate runners without accumulating
log handlers across tests, plus a DummyScript test double.
Fixes#22125
Add test coverage for Django management commands across core, dcim,
extras, ipam, and utilities apps.
Tests verify command argument handling, error cases, and integration
with mocked dependencies using patches and test doubles.
Fixes#22124