Skip to content

Conversation

@arthanson
Copy link
Collaborator

@arthanson arthanson commented Dec 10, 2025

Fixes: #20875

Several cases were previously missed:

  • netbox/dcim/models/devices.py - when components are instantiated from the device-template and the denormalized fields were never getting updated.
  • netbox/dcim/models/modules.py - when creating a module and instantiating components
  • netbox/dcim/signals.py - when changing the site for a location, when changing the site for a rack

Also checked the API and it looks like the API and this should also affect those. Bulk updates on the API do serializer.save() on each object which will cause the signal handler to run.

@arthanson arthanson changed the title DRAFT: #20875 fix updating of denormalized fields (_site, _location, _rack) for component models #20875 fix updating of denormalized fields (_site, _location, _rack) for component models Dec 10, 2025
@arthanson arthanson marked this pull request as ready for review December 10, 2025 18:46
@arthanson arthanson requested review from a team, jeremystretch and jnovinger and removed request for a team December 10, 2025 18:46
Copy link
Member

@jnovinger jnovinger left a comment

Choose a reason for hiding this comment

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

I think I agree with @jeremystretch's suggestion about populating fields in instantiate(). I see two distinct problems here that may not need the same solution:

  1. Device/Module creation

When components are instantiated via bulk_create(), the denormalized fields are NULL. Jeremy's suggestion handles this populate _site, _location, and _rack in each template's instantiate() method so the fields are set correctly before bulk_create() is called. No post-processing UPDATE needed.

  1. Location/Rack changes (signal handlers)

The helper function creates an O(m * n) query pattern here. When a location's site changes with 100 devices, this executes 1,000 UPDATE queries (100 devices × 10 component models). The signal handlers could instead bulk-update per component model (see suggestion in other comment for how I'd approach that).

Given that needed change of behavior, I don't think the helper function provides enough value to justify abstracting these two distinct patterns. Case 1 can be handled in instantiate(), and Case 2 needs efficient bulk updates.

Although, perhaps I'm missing something here. Let me know.

@arthanson arthanson requested a review from jnovinger December 12, 2025 18:35
@jnovinger jnovinger merged commit ec13a79 into main Dec 12, 2025
10 checks passed
@jnovinger jnovinger deleted the 20875-device-components branch December 12, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interface does not appear under interfaces' site filter

4 participants