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

Add unique field prevalidation #16

Closed

Conversation

florimondmanca
Copy link
Member

Fixes #11

TBH, looking at the implementation I was thinking this could be something that typesystem could provide a framework for.

For example, provide hook method such as async def validate_unique_field(name, value):, which wouldn't to anything by default, and allow Schema subclasses (Model in this case) to override it to perform any calls required to check the uniqueness constraint.

@tomchristie
Copy link
Member

For example, provide hook method

Indeed, yup. Also really we'll want to make sure that any uniqueness errors are included alongside any other errors, rather than only running uniqueness validation once everything else passes.

Will need to think about this one a bit.

@tomchristie
Copy link
Member

Plus we'll want to include the same validation on update too, but excluding pk=instance.pk

@florimondmanca
Copy link
Member Author

@tomchristie I added uniqueness validation in .update() too. The way I did it was to create a subclass of typesystem.Object which allows to see how the "hook" thing could look. :-) All errors are now returned as one exception too.

@florimondmanca florimondmanca mentioned this pull request Mar 29, 2019
@florimondmanca
Copy link
Member Author

Hi @tomchristie, I realize this PR has been around for a while — are there any blockers here? I suppose the fact that this PR works around TypeSystem not providing async validation may be one. Happy to receive any pointers on how to tackle/clean this up, either here on in TypeSystem.

@aminalaee aminalaee closed this Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pre-validate uniqueness.
3 participants