JSON not serialized in prepared reactive query
See original GitHub issueHi,
I am not sure if this is a bug report or a question.
For reasons we are currently trying to use a psql table with a single JSON column and some constraints on the id
field of the data:
CREATE TABLE contracts (
json JSONB NOT NULL,
CONSTRAINT validate_id CHECK( json ? 'id' )
);
CREATE UNIQUE INDEX contracts_ids_idx ON contracts( (json ->> 'id') );
Our relevant Java code (including code for a non-prepared version) in the respective write routine looks like this:
import io.reactiverse.reactivex.pgclient.PgPool;
import io.reactiverse.reactivex.pgclient.data.Json;
import io.vertx.core.json.JsonObject;
public class ContractRepository {
private final PgPool pool; //instantiated outside the posted code
private static final String CREATE_QUERY = "INSERT INTO contracts (json) VALUES ($1);";
private static final String CREATE_QUERY_NOT_PREPARED = "INSERT INTO contracts (json) VALUES ('%s');";
public Single<UUID> rxStoreNewContract(Contract contract) {
UUID uuid = contract.getId();
return Single.just(contract)
.map(JsonObject::mapFrom)
.map(Json::create)
.flatMap( foo -> pool.rxPreparedQuery(CREATE_QUERY, Tuple.of(foo)) )
//.flatMap(foo -> pool.rxQuery(String.format(CREATE_QUERY_NOT_PREPARED, foo)))
.map(ar -> uuid);
}
}
The non-prepared commented version works fine.
And if I run this code and inspect foo
in the debugger, it looks fine too (see attached screenshot).
But the db complains about a null
value in the json
column:
06:42:59.688 [vert.x-eventloop-thread-0] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: null value in column "json" violates not-null constraint
io.reactiverse.pgclient.PgException: null value in column "json" violates not-null constraint
at io.reactiverse.pgclient.impl.QueryCommandBase.handleErrorResponse(QueryCommandBase.java:65)
at io.reactiverse.pgclient.impl.codec.decoder.MessageDecoder.decodeError(MessageDecoder.java:253)
at io.reactiverse.pgclient.impl.codec.decoder.MessageDecoder.decodeMessage(MessageDecoder.java:142)
at io.reactiverse.pgclient.impl.codec.decoder.MessageDecoder.channelRead(MessageDecoder.java:122)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
I tried to trace the code in the debugger but pretty soon got lost. So I can’t say if this is a bug or whether we are “holding it wrong”.
We are running this in Micronaut and Micronauts preconfigured reactive-pg-client
version is 0.10.5 . Updating to 0.10.9 didn’t help and updating to 0.11.2 left us with some runtime exceptions that are probably solvable but we didn’t pursue.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top GitHub Comments
thanks @agschaid
see https://github.com/eclipse-vertx/vertx-sql-client/issues/320 - I will close this issue.