nautobot-app-data-validation-engine icon indicating copy to clipboard operation
nautobot-app-data-validation-engine copied to clipboard

Plugin reports all possible data validators as in use

Open mzbroch opened this issue 1 year ago • 4 comments

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

mzbroch avatar May 31 '23 08:05 mzbroch

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 avatar Jun 01 '23 16:06 DistantVoyager

@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.

mzbroch avatar Jun 02 '23 06:06 mzbroch

@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.

DistantVoyager avatar Sep 28 '23 19:09 DistantVoyager

@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.

mzbroch avatar Sep 29 '23 11:09 mzbroch