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

validate_unique() is not enforced during API validation #4340

Closed
lampwins opened this issue Mar 10, 2020 · 1 comment
Closed

validate_unique() is not enforced during API validation #4340

lampwins opened this issue Mar 10, 2020 · 1 comment
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@lampwins
Copy link
Contributor

Environment

  • Python version: 3.7
  • NetBox version: 2.7.10

Steps to Reproduce

  1. Create a virtualization cluster
  2. In the API, create a VM with the name "vm1" and assigned to the cluster in step 1
  3. In the API, create a second VM with the same name "vm1" and assigned to the same cluster from step 1

Expected Behavior

The unique constraint placed on VM name, cluster, and tenant should prevent the second VM from being created. This is true in the web UI.

Observed Behavior

The API validation ignores this unique constraint because of our use of validate_unique() on the virtual machine model. Django's ModelForm class does account for calling validate_unique() but we have implemented our own model validation in the API by way of ValidatedModelSerializer and it does not make a call to validate_unique(). We just need to call instance.validate_unique() after instance.clean()

@lampwins lampwins added status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application labels Mar 10, 2020
@lampwins
Copy link
Contributor Author

To clarify, the reason the unique constraint is "ignored" is because in NULL != NULL in unique comparisons which is why we have to implement validate_unique() in the first place to account for the possible null tenant field.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

1 participant