Open Azmodeszer opened 2 weeks ago
- Create a custom validator as described here
Please replicate the exact reproduction steps in your initial post above.
@jeremystretch
from extras.validators import CustomValidator
class webmintagging(CustomValidator):
def validate(self, instance, request):
if ("webmin-autoupdates".upper() in [tag.slug.upper() for tag in instance._m2m_values['tags']] or "webmin-autosecupdates".upper() in [tag.slug.upper() for tag in instance._m2m_values['tags']]) and not "webmin".upper() in [tag.slug.upper() for tag in instance._m2m_values['tags']]:
self.fail("Can't add specific Webmin tag without basic Webmin tag!", field='tags')
CUSTOM_VALIDATORS = {
'dcim.device': (
'scripts.custom_validators.webmintagging.webmintagging',
),
'virtualization.virtualmachine': (
'scripts.custom_validators.webmintagging.webmintagging',
),
}
sudo systemctl restart netbox
Maybe something to do with the fact that for bulk edits the field splits into "Add tags" and "Remove tags"?
Just an FYI, I can replicate this issue and confirm the custom validator breaks bulk editing regardless of whether or not tags are added or removed in the bulk edit request (i.e. just changing the description
field).
Here's the validator we have in place:
class GroupValidator(CustomValidator):
def validate(self, instance):
# Group is required unless the instance is tagged with 'Exception'
if not instance.group and 'exception' not in [tag.name.lower() for tag in instance._m2m_values['tags']]:
self.fail('Custom validation: Group is required.', field='group')
The issue appears to be that the _m2m_values
dictionary is empty.
Deployment Type
Self-hosted
NetBox Version
v.4.0.9
Python Version
3.11
Steps to Reproduce
Expected Behavior
Edit works as it does for single edits.
Observed Behavior