Skip to content
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

Plugin reports all possible data validators as in use #69

Open
mzbroch opened this issue May 31, 2023 · 4 comments
Open

Plugin reports all possible data validators as in use #69

mzbroch opened this issue May 31, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@mzbroch
Copy link
Contributor

mzbroch commented May 31, 2023

Environment

  • Python version:
  • Nautobot version: 2.0 (next from 2023-05-31)
  • nautobot-data-validation-engine version: branch next-2.0

Expected Behavior

Plugin shows only model defined through DataComplianceRule created in custom_validators.py

Observed Behavior

Plugin shows all models under Data Validators

Steps to Reproduce

  1. In plugin's custom_validators.py create following :
class DeviceDataComplianceRules(DataComplianceRule):
    model = "dcim.device"
    enforce = False

    # Checks if a device name contains any special characters other than a dash (-), underscore (_), or period (.) using regex
    def audit_device_name_chars(self):
        if not re.match("^[a-zA-Z0-9\-_.]+$", self.context["object"].name):
            raise ComplianceError({"name": "Device name contains unallowed special characters."})

    # Checks if a device is not assigned to a rack
    def audit_device_rack(self):
        if not self.context["object"].rack:
            raise ComplianceError({"rack": "Device should be assigned to a rack."})

    def audit(self):
        messages = {}
        for fn in [self.audit_device_name_chars, self.audit_device_rack]:
            try:
                fn()
            except ComplianceError as ex:
                messages.update(ex.message_dict)
        if messages:
            raise ComplianceError(messages)


custom_validators = list(CustomValidatorIterator()) + [DeviceDataComplianceRules]
  1. Navigate to Installed Plugins -> , click on details
Screenshot 2023-05-31 at 10 05 19
@DistantVoyager
Copy link
Contributor

DistantVoyager commented Jun 1, 2023

I could be wrong, but I think this is expected behavior and is just the inner workings of DVE. The Data Compliance feature was just added in v2.1.0 and this long list of data validators was still present in previous versions (i.e. I don't believe this is generated based on provided Data Compliance rules).

v2.1.0:
image

v2.0.1:
image

@lampwins - can you confirm that it's expected for DVE to show all models under Data Validators?

@DistantVoyager DistantVoyager added the question Further information is requested label Jun 1, 2023
@mzbroch
Copy link
Contributor Author

mzbroch commented Jun 2, 2023

@DistantVoyager The reported issue impacts all plugins.

If I create a custom plugin (other than the data validation plugin), and define a DataComplianceRule within this plugin, it nautobot will report all data validators for this specific plugin.

This is an issue, as in an example given only dcim.device should be data-validated.

@DistantVoyager DistantVoyager added bug Something isn't working nautobot 2.0 and removed question Further information is requested labels Jun 7, 2023
@DistantVoyager DistantVoyager added this to the Nautobot v2 milestone Jun 12, 2023
@DistantVoyager
Copy link
Contributor

DistantVoyager commented Sep 28, 2023

@mzbroch - do I need to do anything with this issue you opened a while back? Or is it fine to close? Not sure if it was ever resolved among all the plugins, but maybe it's not crucial.

@mzbroch
Copy link
Contributor Author

mzbroch commented Sep 29, 2023

@mzbroch - do I need to do anything with this issue you opened a while back? Or is it fine to close? Not sure if it was ever resolved among all the plugins, but maybe it's not crucial.

So requires re-visiting, let's fix it and close.

@DistantVoyager DistantVoyager removed this from the Nautobot v2 milestone Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants