-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Custom model validation exposed through plugins #4393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm going to punt on this for the initial implementation as there's already a lot going on. Let's put a pin in this until we figure out how we're going to handle feature requests for the plugins framework after the v2.8 release. |
@jeremystretch can we pick this back up given the relatively light load of plugins related requests? I am happy to take this on. |
Blocked by #4640 |
To further provide some use cases, here are a few I have noted with customers recently Enforcing Business logic
Many users "expect" the IPAM component to operate in a certain way. While it is clear that the base implementation cannot support that logic in order to support many more use cases, within the custom model validation you can add these capabilities.
|
Closing this in favor of #5963, since it doesn't seem practical to require users to develop an entire plugin just to enforce model validation. |
Environment
Proposed Functionality
Expose a plugin interface that allows for custom model validation to be performed when the model's
clean()
method is called. This interface will look similar to the plugin template content injection interface in which plugin developers specify the model they wish to act on. In this case, the class will implement only a single methodvalidate()
:As you can see, this method can either raise
VailidationError
or simply returnNone
if the object passes validation. In the code path, these custom validators will be run at the end of the model's standardclean()
method.Use Case
As users adopt NetBox as a core component in automation solutions, data validity is key. NetBox reports can be used to highlight data consistency and integrity issues, but users must still fix these problems after the fact. By enforcing business logic rules when an object is created or updated, the chances of producing bad data are reduced.
The desire to implement custom validation has come up several times in the community before, but we have not really had a clean enough way to implement this until the plugins framework was born.
See: this comment, #3974, #3163, etc.
Database Changes
None
External Dependencies
The plugins framework introduced in 2.8.
The text was updated successfully, but these errors were encountered: