quarkus: Regression Test: Validation errors on Reactive routes are no longer propagated
Describe the bug
Having these two routes:
@Inject
FruitResource fruitResource;
@Route(methods = HttpMethod.POST, path = "/insert")
void insert(@Body Fruit fruit, RoutingContext context) {
fruitResource.insertFruit(fruit)
.onFailure().invoke(context::fail)
.subscribe().with(id -> context.response().setStatusCode(201).end());
}
@Route(path = "/*", type = Route.HandlerType.FAILURE, produces = "application/json")
void databaseConstraintFailure(PgException e, HttpServerResponse response) {
response.setStatusCode(400).end();
}
The insert route will insert a fruit item into the database. The databaseConstraintFailure handler will map the database constraints into a 400 Status code.
The above scenario works fine using 1.13.1.Final or later, but not using 999-SNAPSHOT which fails with the next exception:
ERROR: HTTP Request to /insert failed, error id: f1aab3c8-a7f2-464d-8c33-bd4a33af5e31-1
io.vertx.core.VertxException: Transaction already completed
at io.vertx.sqlclient.impl.TransactionImpl.checkPending(TransactionImpl.java:115)
at io.vertx.sqlclient.impl.TransactionImpl.rollback(TransactionImpl.java:154)
at io.vertx.sqlclient.impl.TransactionImpl.rollback(TransactionImpl.java:159)
at io.vertx.mutiny.sqlclient.Transaction.lambda$rollback$2(Transaction.java:112)
at io.smallrye.mutiny.vertx.AsyncResultUni.subscribe(AsyncResultUni.java:30)
at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:37)
at io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni.subscribe(UniOnItemTransformToUni.java:25)
at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:37)
at io.smallrye.mutiny.operators.uni.UniOnItemOrFailureFlatMap$UniOnItemOrFailureFlatMapProcessor.performInnerSubscription(UniOnItemOrFailureFlatMap.java:99)
at io.smallrye.mutiny.operators.uni.UniOnItemOrFailureFlatMap$UniOnItemOrFailureFlatMapProcessor.onFailure(UniOnItemOrFailureFlatMap.java:65)
at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:44)
at io.smallrye.mutiny.vertx.AsyncResultUni.lambda$subscribe$1(AsyncResultUni.java:36)
at io.vertx.mutiny.sqlclient.PreparedQuery$2.handle(PreparedQuery.java:140)
at io.vertx.mutiny.sqlclient.PreparedQuery$2.handle(PreparedQuery.java:135)
at io.vertx.core.impl.future.FutureImpl$3.onFailure(FutureImpl.java:128)
at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:79)
at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:198)
at io.vertx.core.impl.future.PromiseImpl.tryFail(PromiseImpl.java:23)
at io.vertx.sqlclient.impl.QueryResultBuilder.tryFail(QueryResultBuilder.java:118)
at io.vertx.core.Promise.fail(Promise.java:89)
at io.vertx.core.Promise.handle(Promise.java:53)
at io.vertx.sqlclient.impl.TransactionImpl.lambda$null$0(TransactionImpl.java:75)
at io.vertx.core.impl.future.FutureImpl$3.onSuccess(FutureImpl.java:124)
at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:62)
To Reproduce
Steps to reproduce the behavior:
- git clone
https://github.com/Sgitario/quarkus-examples - cd quarkus-examples/reproducers/reactive-sql
- mvn clean verify -Dtest=FruitResourceTest#shouldNotInsertFruitIfValidationError
The test should pass, but it’s failing with the above exception
Quarkus version or git rev
999-SNAPSHOT
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 28 (26 by maintainers)
Commits related to this issue
- SqlClientHelper: fix transaction management Related to https://github.com/quarkusio/quarkus/issues/16430 When a problem occurs on the DB side (e.g. constraint violation), the SqlClientHelper impleme... — committed to tsegismont/smallrye-mutiny-vertx-bindings by tsegismont 3 years ago
- Uncomment coverage as 16430 issue has been fixed The issue https://github.com/quarkusio/quarkus/issues/16430 has been fixed in Upstream, so we can verify the fix by uncommenting the test case. — committed to Sgitario/beefy-scenarios by Sgitario 3 years ago
See https://github.com/quarkusio/quarkus/pull/17113/commits/a38ce98b8abccc3f64431e924e240a3e43562558
Just merged @tsegismont fix at https://github.com/smallrye/smallrye-reactive-utils/pull/312
@cescoffier @jponge 🤦 thank you both!
@cescoffier @jponge here’s the fix https://github.com/smallrye/smallrye-reactive-utils/pull/312