refactor: enhance db existence validation #1350
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some refactoring in validators. Some of them are not used anymore or they do check for the existence of the DB by fetching the record, which is inefficient. DRF validators are expected to raise
ValidationError
or return None. In case of theorganization_id
has been created a mixin to avoid code duplication.Refactored:
Removed:
Technically, in most of the cases a PrimaryKey field would be better, but that would require a more extended refactor to keep 100% backward compatibility, since we would have to implement custom error messages among other changes. There are multiple fields candidate to be a PrimaryKeyField and such a conversion is not the scope of this PR.
Here I only address the fields were we are duplicating DB queries, duplicating field definition and removing unused validators.