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

Support validating the set of tags on an object #1

Open
progala opened this issue May 14, 2021 · 4 comments
Open

Support validating the set of tags on an object #1

progala opened this issue May 14, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@progala
Copy link

progala commented May 14, 2021

Environment

  • Python version: 3.8.5
  • Nautobot version: 1.0.1
  • nautobot-plugin-data-validation-engine: 1.0.0-dev

Steps to Reproduce

  1. Create regex rule for Object allowing tags, e.g. ipam.VLAN
  2. Specify "tags" as the Field
  3. Specify simple regex e.g. "data" as Regular expression

Example rule used for testing:

image

Expected Behavior

One of two outcomes should happend:

  1. When new VLAN is created and tag matching regex is added new object should be created without errors.
  2. When new VLAN is created and added tag does NOT match regex a validation error should be raised.

Observed Behavior

TypeError is raised: "expected string or bytes-like object"

image

Full traceback:

Internal Server Error: /ipam/vlans/add/
Traceback (most recent call last):
  File "/opt/nautobot/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/opt/nautobot/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/nautobot/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/nautobot/lib/python3.8/site-packages/nautobot/core/views/generic.py", line 266, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/nautobot/lib/python3.8/site-packages/nautobot/utilities/views.py", line 94, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/nautobot/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/nautobot/lib/python3.8/site-packages/nautobot/core/views/generic.py", line 293, in post
    if form.is_valid():
  File "/opt/nautobot/lib/python3.8/site-packages/django/forms/forms.py", line 177, in is_valid
    return self.is_bound and not self.errors
  File "/opt/nautobot/lib/python3.8/site-packages/django/forms/forms.py", line 172, in errors
    self.full_clean()
  File "/opt/nautobot/lib/python3.8/site-packages/django/forms/forms.py", line 376, in full_clean
    self._post_clean()
  File "/opt/nautobot/lib/python3.8/site-packages/django/forms/models.py", line 405, in _post_clean
    self.instance.full_clean(exclude=exclude, validate_unique=False)
  File "/opt/nautobot/lib/python3.8/site-packages/django/db/models/base.py", line 1216, in full_clean
    self.clean()
  File "/opt/nautobot/lib/python3.8/site-packages/nautobot/extras/plugins/validators.py", line 34, in wrapper
    custom_validator(model_instance).clean()
  File "/opt/nautobot/lib/python3.8/site-packages/nautobot_data_validation_engine/custom_validators.py", line 35, in clean
    if not re.match(rule.regular_expression, getattr(obj, rule.field)):
  File "/usr/lib/python3.8/re.py", line 191, in match
    return _compile(pattern, flags).match(string)
TypeError: expected string or bytes-like object
@lampwins
Copy link
Member

Thanks. I have addressed this immediate bug by not allowing manager-type fields to be used with regex rules (they wouldn't work this way anyway). The use case however, is very interesting and we can create a new rule type with allows for constraining the set of tags that can be added to an object.

@lampwins
Copy link
Member

I played with the idea of a "tag list" validation rule, but the major roadblock is that tags are a many-to-many relationship and thus we can't access them on an object in the clean() method. I will brainstorm some ways we can deal with this.

@lampwins lampwins changed the title Regex validation of "tags" field results in the TypeError Support validating the set of tags on an object May 28, 2021
@DistantVoyager DistantVoyager added the question Further information is requested label May 24, 2023
@DistantVoyager
Copy link
Contributor

Is this issue still relevant or should it be closed?

@DistantVoyager DistantVoyager closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2023
@glennmatthews
Copy link
Contributor

I think this should be reopened - to the best of my knowledge M2M validation isn't a solved problem yet in this App?

@DistantVoyager DistantVoyager added enhancement New feature or request and removed question Further information is requested labels May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants