Skip to content

Document persisted despite throwing ConstraintViolationException on save. #1206

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

Closed
fvalton opened this issue Aug 26, 2021 · 2 comments · Fixed by #1207
Closed

Document persisted despite throwing ConstraintViolationException on save. #1206

fvalton opened this issue Aug 26, 2021 · 2 comments · Fixed by #1207
Labels
type: regression A regression from a previous release

Comments

@fvalton
Copy link

fvalton commented Aug 26, 2021

An issue exists in the below versions of spring data and SDK whereby documents failing constraint validations are still persisted to Couchbase - despite these violations being picked up & printed to stderr.

Line 65 of ValidatingCouchbaseEventListener throws a new ConstraintViolationException when constraint violations are detected.

Further up the exception handling chain at line 186 of CouchbaseTemplateSupport the exception is swallowed and the stacktrace simply printed.

This allows the document to be saved to Couchbase even though it fails validation.

The exception should be propagated up the call chain to interrupt the save operation. This was the earlier behaviour in spring data 3.2.6.

Spring-Data: 4.2.4 (and 4.0.3)
Java SDK: 3.1.6

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 26, 2021
@mikereiche mikereiche added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 26, 2021
@mikereiche
Copy link
Collaborator

Thanks for opening this issue.

@mikereiche
Copy link
Collaborator

mikereiche commented Aug 26, 2021

Note to self: added this for validation

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>6.2.0.Final</version>
</dependency>

<dependency>
    <groupId>javax.el</groupId>
    <artifactId>javax.el-api</artifactId>
    <version>3.0.0</version>
</dependency>

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.el</artifactId>
    <version>3.0.0</version>
</dependency>
@Bean
public LocalValidatorFactoryBean validator() {
	return new LocalValidatorFactoryBean();
}

@Bean
public ValidatingCouchbaseEventListener validationEventListener() {
	return new ValidatingCouchbaseEventListener(validator());
}
@Max(2)
long size;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants