[PR #11698] [MERGED] Fixes #11032 - Replication fields broken in custom validation #13828

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/11698
Author: @kkthxbye-code
Created: 2/8/2023
Status: Merged
Merged: 2/8/2023
Merged by: @jeremystretch

Base: developHead: 11032-fix-custom-validation-replicated


📝 Commits (2)

  • a1ff380 Fixes #11032 - Replication fields broken in custom validation
  • a4700bc Use getattr instead of hasattr to make sure custom validation is triggered as normal

📊 Changes

2 files changed (+8 additions, -0 deletions)

View changed files

📝 netbox/netbox/models/features.py (+4 -0)
📝 netbox/netbox/views/generic/object_views.py (+4 -0)

📄 Description

Fixes: #11032

The issue here is that validation is triggered on the base instance when the form uses replication_fields. So if the user creates a vminterface with name test[1-2] validation is triggered for:

VMInterface with no name
VMInterface with name test1
VMInterface with name test2

For the normal validation this works okay, but for custom validation it results in the validator being triggered for the first VMInterface which is never actually saved. Not sure if there is a smarter way to fix this, my approach is to tag the instance that is never going to be saved with a private variable and make sure we don't run custom validators for these instances.


🔄 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/11698 **Author:** [@kkthxbye-code](https://github.com/kkthxbye-code) **Created:** 2/8/2023 **Status:** ✅ Merged **Merged:** 2/8/2023 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `11032-fix-custom-validation-replicated` --- ### 📝 Commits (2) - [`a1ff380`](https://github.com/netbox-community/netbox/commit/a1ff3800c7491a652e39c6529becae41162267bd) Fixes #11032 - Replication fields broken in custom validation - [`a4700bc`](https://github.com/netbox-community/netbox/commit/a4700bc498398d87e614eaf68a27f625f75802b5) Use getattr instead of hasattr to make sure custom validation is triggered as normal ### 📊 Changes **2 files changed** (+8 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `netbox/netbox/models/features.py` (+4 -0) 📝 `netbox/netbox/views/generic/object_views.py` (+4 -0) </details> ### 📄 Description ### Fixes: #11032 The issue here is that validation is triggered on the base instance when the form uses `replication_fields`. So if the user creates a vminterface with name test[1-2] validation is triggered for: VMInterface with no name VMInterface with name test1 VMInterface with name test2 For the normal validation this works okay, but for custom validation it results in the validator being triggered for the first VMInterface which is never actually saved. Not sure if there is a smarter way to fix this, my approach is to tag the instance that is never going to be saved with a private variable and make sure we don't run custom validators for these instances. --- <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:21:02 +01:00
adam closed this issue 2025-12-29 23:21:02 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#13828