-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fixes #17954 - Add dynamic parent resolution for cable CSV imports #20843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fixes #17954 - Add dynamic parent resolution for cable CSV imports #20843
Conversation
d1c9288 to
7237bbe
Compare
Replace device-specific fields with generic parent fields to support circuits, power panels, and other cable termination types.
7237bbe to
c111c08
Compare
jeremystretch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this @jsenecal. It's a novel approach, however I don't think it quite addresses the concerns raised under #17995.
Ideally, we want to support the dynamic assignment of objects using a minimal set of fields. I would expect these to be:
side_x_type: The type of the terminating objectside_x: The object identifier, supporting an arbitrary accessor (e.g.nameorpk) selected by the userside_x_parent: The parent object identifier, likewise supporting an arbitrary accessor
We want to avoid forcing the use of a specific attribute for any particular object to ensure flexibility and maintain consistency with similar import forms.
The other major consideration in play here (which admittedly is absent from #17954) is support for declaring multiple terminating objects at either end of a cable. Even if we solve the immediate concern of parent object identification, it would be a half-measure at best unless we can also support the attachment of multiple terminations. I'm not sure we have a pattern for this yet, but presumably it would involve employing CSVModelMultipleChoiceField for the terminating objects and dynamically adjusting its queryset on form initialization.
Have you done any exploration in that area?
Hi @jeremystretch , I actually went with the Handling multiple objects at a time was out of scope on this and I was planning on opening a different issue/PR for that. The idea would we to support those using standard json arrays, or simple single string for reverse compatibility. Let me know if you'd like me to include this in this PR. The current approach does everything in the "clean" phase of the form and allows great flexibility. |
|
I just realized my usage example in the PR is outdated - my bad! Let me update that real quick 😅 |
Fixes: #17954
Overview
This PR implements dynamic parent resolution for cable CSV imports, enabling bulk import of cables connected to circuits, power panels, and devices. This is a revised approach following PR #17995, which was closed due to design concerns.
Key Difference from PR #17995:
Instead of adding separate fields for each parent type (
side_x_circuit,side_x_power_panel), this implementation uses dynamic parent resolution by repurposing the existingside_x_devicefield toside_x_parent. The parent object (Circuit, Device, or PowerPanel) is determined based on the termination type specified.Implementation Details
1. Dynamic Parent Field Resolution:
side_x_devicetoside_x_parentinCableImportFormside_x_typedcim.Device→ Resolves using Device model (for interfaces, console ports, power ports, etc.)circuits.Circuit→ Resolves using Circuit model (for circuit terminations)dcim.PowerPanel→ Resolves using PowerPanel model (for power feeds)2. Parent-Specific Lookup Logic:
cid(Circuit ID) as the lookup fieldnameas the lookup fieldnameas the lookup field3. Enhanced Validation:
4. Comprehensive Test Coverage:
Benefits
side_x_devicetoside_x_parent)Usage Examples
Device to Device (Interface to Interface):
Circuit Termination to Device Interface:
Power Feed to Power Port:
With Site Scoping (for non-unique device names):