[PR #18874] [MERGED] Fixes: #18833 Inventory Item Bulk Import - 'InventoryItemImportForm' has no field named 'component_id'. #15463

Closed
opened 2025-12-30 00:22:05 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/18874
Author: @renatoalmeidaoliveira
Created: 3/12/2025
Status: Merged
Merged: 3/19/2025
Merged by: @jeremystretch

Base: mainHead: 18833-Inventory-Item-Bulk-Import-'component_id'


📝 Commits (4)

  • f62b2c7 Refactor InventoryItemImportForm clean method
  • ef9886b Add super().clean(); renamed content_type; simplified component creation
  • d327147 Fix missing component_name issue
  • c8f82c2 Update netbox/dcim/forms/bulk_import.py

📊 Changes

1 file changed (+36 additions, -18 deletions)

View changed files

📝 netbox/dcim/forms/bulk_import.py (+36 -18)

📄 Description

Fixes: #18833 Inventory Item Bulk Import - 'InventoryItemImportForm' has no field named 'component_id'.

Root Cause:

In Django's BaseModelForm _post_clean method, an instance of the model is created with data from self.cleaned_data. After the model instantiation, the full_clean() method is executed on that model instance.
Since component_type is a field of the InventoryItem model, the execution of full_clean() on the instance was failing without being captured by any form validation method.

Solution:

In Django's form validation process, the clean_<fieldname>() methods are executed before the clean_form() method. Inside the clean_<fieldname>() method, there are no guarantees about which field names have already been processed and is available at self.cleaned_data.And to fully validate component_type use cases, the device, component_type, and component_name fields must be available.

To fix the validation process, the clean_component_name method was replaced by the clean method, and the fields component_name and component_type were removed from cleaned_data when incorrect data was provided.


🔄 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/18874 **Author:** [@renatoalmeidaoliveira](https://github.com/renatoalmeidaoliveira) **Created:** 3/12/2025 **Status:** ✅ Merged **Merged:** 3/19/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `main` ← **Head:** `18833-Inventory-Item-Bulk-Import-'component_id'` --- ### 📝 Commits (4) - [`f62b2c7`](https://github.com/netbox-community/netbox/commit/f62b2c7552c5af8d696b898111fab6127d6205ef) Refactor InventoryItemImportForm clean method - [`ef9886b`](https://github.com/netbox-community/netbox/commit/ef9886b618255b9d4c7d90f379dda5fa0625b380) Add super().clean(); renamed content_type; simplified component creation - [`d327147`](https://github.com/netbox-community/netbox/commit/d327147ccf2acd580fd58f873af1fde32d4131b5) Fix missing component_name issue - [`c8f82c2`](https://github.com/netbox-community/netbox/commit/c8f82c23afabf36d4dbcbf135e9be17476fd6910) Update netbox/dcim/forms/bulk_import.py ### 📊 Changes **1 file changed** (+36 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/forms/bulk_import.py` (+36 -18) </details> ### 📄 Description ### Fixes: #18833 Inventory Item Bulk Import - 'InventoryItemImportForm' has no field named 'component_id'. ### Root Cause: In Django's `BaseModelForm` `_post_clean` method, an instance of the model is created with data from `self.cleaned_data`. After the model instantiation, the `full_clean()` method is executed on that model instance. Since `component_type` is a field of the `InventoryItem` model, the execution of `full_clean()` on the instance was failing without being captured by any form validation method. ### Solution: In Django's form validation process, the `clean_<fieldname>()` methods are executed before the `clean_form()` method. Inside the `clean_<fieldname>()` method, there are no guarantees about which field names have already been processed and is available at `self.cleaned_data`.And to fully validate `component_type` use cases, the `device`, `component_type`, and `component_name` fields must be available. To fix the validation process, the `clean_component_name` method was replaced by the `clean` method, and the fields `component_name` and `component_type` were removed from `cleaned_data` when incorrect data was provided. --- <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-30 00:22:05 +01:00
adam closed this issue 2025-12-30 00:22:05 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15463