[PR #14514] [MERGED] Fixes #14482 - Fix validation error when primary IP is moved #14397

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/14514
Author: @DanSheps
Created: 12/13/2023
Status: Merged
Merged: 12/28/2023
Merged by: @jeremystretch

Base: developHead: 14482-ipaddress-move-return-validation-error


📝 Commits (7)

  • 8f8f05a Fix validation when primary IP is moved.
  • 366351d Fix views test
  • 6aa4670 Work on excluding assigned_objects
  • b9b24d9 Modify clean() on model and form to properly catch error
  • 9374890 Fix test failure
  • ec58b53 Fix test to check for PK
  • 2cc35b4 Remove model_form check

📊 Changes

1 file changed (+3 additions, -5 deletions)

View changed files

📝 netbox/ipam/models/ip.py (+3 -5)

📄 Description

Fixes: #14482

When an Primary IP address is moved, it should result in a validation error. However, it does not normally due to the fact that the clean() method on the model returns with the field assigned_object instead of interface, vminterface, or fhrpgroup. When the _post_clean() method tries to resolve the fields, it will fail because the form does not contain assigned_object as a field and returns a ValueError.

This will correctly map the assigned_object field to the correct field, however we should maybe look at instead providing a method to have assigned_object (or similar GFK fields) as proper form fields in the future, perhaps using a custom form field.


🔄 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/14514 **Author:** [@DanSheps](https://github.com/DanSheps) **Created:** 12/13/2023 **Status:** ✅ Merged **Merged:** 12/28/2023 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `14482-ipaddress-move-return-validation-error` --- ### 📝 Commits (7) - [`8f8f05a`](https://github.com/netbox-community/netbox/commit/8f8f05af258feb32928908c1c5edd753eea9b3a8) Fix validation when primary IP is moved. - [`366351d`](https://github.com/netbox-community/netbox/commit/366351dd23d9cbcdfb0e72d2cc287017fe5b3753) Fix views test - [`6aa4670`](https://github.com/netbox-community/netbox/commit/6aa4670c399887ae7dd0a6e94fe5f39049e3229e) Work on excluding assigned_objects - [`b9b24d9`](https://github.com/netbox-community/netbox/commit/b9b24d9399eb6fc63dadde085149c0f847a8b492) Modify clean() on model and form to properly catch error - [`9374890`](https://github.com/netbox-community/netbox/commit/93748907249922f9e066d991dcbe0c310728603d) Fix test failure - [`ec58b53`](https://github.com/netbox-community/netbox/commit/ec58b5338f32d2922d81a3510087d526c165c447) Fix test to check for PK - [`2cc35b4`](https://github.com/netbox-community/netbox/commit/2cc35b4e9f23f50f14a8fa743d141c28919c77b0) Remove model_form check ### 📊 Changes **1 file changed** (+3 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `netbox/ipam/models/ip.py` (+3 -5) </details> ### 📄 Description ### Fixes: #14482 When an Primary IP address is moved, it should result in a validation error. However, it does not normally due to the fact that the `clean()` method on the model returns with the field `assigned_object` instead of `interface`, `vminterface`, or `fhrpgroup`. When the `_post_clean()` method tries to resolve the fields, it will fail because the form does not contain `assigned_object` as a field and returns a ValueError. This will correctly map the `assigned_object` field to the correct field, however we should maybe look at instead providing a method to have `assigned_object` (or similar GFK fields) as proper form fields in the future, perhaps using a custom form field. --- <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:24:14 +01:00
adam closed this issue 2025-12-29 23:24:14 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14397