netbox icon indicating copy to clipboard operation
netbox copied to clipboard

15029 check if duplicate FHRP group assignment

Open arthanson opened this issue 1 year ago • 2 comments

Fixes: #15029

Check for duplicate FHRP group assignment so IntegrityError isn't raised.

arthanson avatar Feb 05 '24 18:02 arthanson

Have you been able to determine why this exception isn't caught, whereas others are? For instance, attempting to create a device with the same name, site, and tenant as an existing device violates a unique constraint on the Device model, but it is caught and raised cleanly as a validation error:

screenshot

The same thing should be happening for FHRP group assignments, without needing any custom code. I suspect it might have to do with a difference in the model and/or form classes used.

jeremystretch avatar Feb 14 '24 14:02 jeremystretch

The error happens from https://github.com/django/django/blob/main/django/forms/models.py#L390 as the fields aren't in the form so Django skips validating the unique constraints for them, dcim ones are in the form. Several different ways to fix this:

  • I looked at putting them into the form as hidden fields, but the code is also needed to set them - IMHO not obvious what the code is for doing it this way.
  • Looked at overriding _get_validation_exclusions but had side-effects.

I think having it in the clean is the most obvious and direct way to fix?

arthanson avatar Mar 14 '24 20:03 arthanson