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

15029 check if duplicate FHRP group assignment #15047

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

arthanson
Copy link
Collaborator

Fixes: #15029

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

@arthanson arthanson marked this pull request as ready for review February 5, 2024 18:47
@jeremystretch
Copy link
Member

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.

@arthanson
Copy link
Collaborator Author

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?

@jeremystretch jeremystretch merged commit fca23c6 into develop Apr 3, 2024
8 checks passed
@jeremystretch jeremystretch deleted the 15029-duplicate-fhrp-group-assignment branch April 3, 2024 18:09
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assigning duplicate FHRP group to interface results in Integrity Error
2 participants