Fix {module} placeholder resolution in module bay position field #81

Closed
opened 2026-04-05 16:21:31 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @mrmrcoleman on 3/25/2026

Fixes: #20467

Summary

Fixes a bug where the {module} placeholder in a ModuleBayTemplate's position field was not being resolved when a module was installed, leaving the literal string {module} in the position value.

The {module} placeholder already worked correctly in the name and label fields — this brings position into parity.

Changes

File Change
dcim/models/device_component_templates.py Add resolve_position() method; consolidate shared resolution logic into _resolve_module_placeholder() to eliminate duplication across resolve_name, resolve_label, and resolve_position
dcim/tests/test_models.py Regression test: module bay template with position='{module}-1' resolves to 1-1 when installed under a parent bay with position 1

Testing

All existing dcim model and form tests pass (60 tests). Added one regression test that verifies:

  1. Create a device type with a module bay (position 1)
  2. Create a module type with a sub-bay template using position='{module}-1'
  3. Install the module — verify the sub-bay's position resolves to 1-1
*Originally created by @mrmrcoleman on 3/25/2026* ### Fixes: #20467 ## Summary Fixes a bug where the `{module}` placeholder in a `ModuleBayTemplate`'s position field was not being resolved when a module was installed, leaving the literal string `{module}` in the position value. The `{module}` placeholder already worked correctly in the `name` and `label` fields — this brings `position` into parity. ## Changes | File | Change | |------|--------| | `dcim/models/device_component_templates.py` | Add `resolve_position()` method; consolidate shared resolution logic into `_resolve_module_placeholder()` to eliminate duplication across `resolve_name`, `resolve_label`, and `resolve_position` | | `dcim/tests/test_models.py` | Regression test: module bay template with `position='{module}-1'` resolves to `1-1` when installed under a parent bay with position `1` | ## Testing All existing dcim model and form tests pass (60 tests). Added one regression test that verifies: 1. Create a device type with a module bay (position `1`) 2. Create a module type with a sub-bay template using `position='{module}-1'` 3. Install the module — verify the sub-bay's position resolves to `1-1`
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#81