[PR #11231] [MERGED] Fixes #11210 - Exception is thrown when trying to CSV import a cable in with occupied terminations #13756

Closed
opened 2025-12-29 23:20:37 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/11231
Author: @kkthxbye-code
Created: 12/19/2022
Status: Merged
Merged: 1/6/2023
Merged by: @jeremystretch

Base: developHead: 11210-fix-cable-import-exception


📝 Commits (1)

  • 6824cd5 Return no terminations if the cable is unsaved

📊 Changes

1 file changed (+8 additions, -0 deletions)

View changed files

📝 netbox/dcim/models/cables.py (+8 -0)

📄 Description

Fixes: #11210

I believe this is caused by the following django change:

https://docs.djangoproject.com/en/4.1/releases/4.1/#reverse-foreign-key-changes-for-unsaved-model-instances

This is the validation logic that is called for new cables that are bulk imported:
3675ad2539/netbox/dcim/models/cables.py (L148-L149)

In the case of occupied terminations, when the following code is reached the self.terminations queryset is called without the cable being saved yet:

3675ad2539/netbox/dcim/models/cables.py (L111-L118)

I'm not sure this is the correct fix. After the fix the following validation errors are provided:

image

Tests passes, but please give this a good look before merging.

Bonus question: Why does the validation failing in CableImportForm not "cancel" the request? Why are the clean methods of the cable still called afterwards (or before)?


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/11231 **Author:** [@kkthxbye-code](https://github.com/kkthxbye-code) **Created:** 12/19/2022 **Status:** ✅ Merged **Merged:** 1/6/2023 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `11210-fix-cable-import-exception` --- ### 📝 Commits (1) - [`6824cd5`](https://github.com/netbox-community/netbox/commit/6824cd586d079b85c527e97d2be199eb4c33d765) Return no terminations if the cable is unsaved ### 📊 Changes **1 file changed** (+8 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/models/cables.py` (+8 -0) </details> ### 📄 Description ### Fixes: #11210 I believe this is caused by the following django change: https://docs.djangoproject.com/en/4.1/releases/4.1/#reverse-foreign-key-changes-for-unsaved-model-instances This is the validation logic that is called for new cables that are bulk imported: https://github.com/netbox-community/netbox/blob/3675ad2539400038af6797140ddca3679b8bca30/netbox/dcim/models/cables.py#L148-L149 In the case of occupied terminations, when the following code is reached the self.terminations queryset is called without the cable being saved yet: https://github.com/netbox-community/netbox/blob/3675ad2539400038af6797140ddca3679b8bca30/netbox/dcim/models/cables.py#L111-L118 I'm not sure this is the correct fix. After the fix the following validation errors are provided: ![image](https://user-images.githubusercontent.com/400797/208376391-686a7a0b-f87a-4eb7-9de3-e72abbbcf8e1.png) Tests passes, but please give this a good look before merging. Bonus question: Why does the validation failing in CableImportForm not "cancel" the request? Why are the clean methods of the cable still called afterwards (or before)? --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 23:20:37 +01:00
adam closed this issue 2025-12-29 23:20:37 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#13756