[PR #14516] [MERGED] Fixes #12731: Support custom validation for many-to-many fields #14400

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

📋 Pull Request Information

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

Base: developHead: 12731-m2m-validation


📝 Commits (6)

📊 Changes

5 files changed (+314 additions, -9 deletions)

View changed files

netbox/extras/tests/test_custom_validation.py (+265 -0)
📝 netbox/extras/validators.py (+23 -3)
📝 netbox/netbox/api/serializers/base.py (+7 -6)
📝 netbox/netbox/forms/base.py (+11 -0)
📝 netbox/netbox/views/generic/bulk_views.py (+8 -0)

📄 Description

Fixes: #12731

  • Override _post_clean() on NetBoxModelForm to store M2M field values on the cleaned instance for reference
  • Extend BulkEditVIew to store M2M fields for validation
  • Extend validate() on ValidatedModelSerializer similar to what we did for forms
  • Introduce a _getattr() method on CustomValidator to reference the _m2m_values instance attribute when evaluating rules which reference many-to-many fields
  • Add tests for custom validation of M2M fields for model forms and serializers

🔄 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/14516 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 12/13/2023 **Status:** ✅ Merged **Merged:** 12/22/2023 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `12731-m2m-validation` --- ### 📝 Commits (6) - [`0dcead4`](https://github.com/netbox-community/netbox/commit/0dcead40e8f91104917c880382fc132fc024e6b2) WIP - [`d592285`](https://github.com/netbox-community/netbox/commit/d592285b98d0092cba581d8cedb0d068569e1a2c) Enforce custom validators during bulk edit - [`ce08e8d`](https://github.com/netbox-community/netbox/commit/ce08e8d437d4e3d2202dca9da85728f28b45b595) Add bulk edit M2M validation test - [`e3365ed`](https://github.com/netbox-community/netbox/commit/e3365ed509e37250f4bc54832a1a1124b1e4a8c5) Clean up tests - [`ba27dbf`](https://github.com/netbox-community/netbox/commit/ba27dbf7933881251d439934e105b896429b388a) Add custom validation test for bulk import - [`6dfa904`](https://github.com/netbox-community/netbox/commit/6dfa90469905170b6b4c34e245cf5ee973dd2411) Misc cleanup ### 📊 Changes **5 files changed** (+314 additions, -9 deletions) <details> <summary>View changed files</summary> ➕ `netbox/extras/tests/test_custom_validation.py` (+265 -0) 📝 `netbox/extras/validators.py` (+23 -3) 📝 `netbox/netbox/api/serializers/base.py` (+7 -6) 📝 `netbox/netbox/forms/base.py` (+11 -0) 📝 `netbox/netbox/views/generic/bulk_views.py` (+8 -0) </details> ### 📄 Description ### Fixes: #12731 - Override `_post_clean()` on NetBoxModelForm to store M2M field values on the cleaned instance for reference - Extend BulkEditVIew to store M2M fields for validation - Extend `validate()` on ValidatedModelSerializer similar to what we did for forms - Introduce a `_getattr()` method on CustomValidator to reference the `_m2m_values` instance attribute when evaluating rules which reference many-to-many fields - Add tests for custom validation of M2M fields for model forms and serializers --- <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:15 +01:00
adam closed this issue 2025-12-29 23:24:16 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14400