lecousin / lc-spring-data-r2dbc

An extension of spring-data-r2dbc to provide features such as relationships, joins, cascading save/delete, lazy loading, sequence, schema generation, composite id
Apache License 2.0
48 stars 12 forks source link

SelectExecution#executeWithoutPreSelect does not pass the reactive context to the fromDb variable, which is why transactions do not work. #28

Open ost-av opened 9 months ago

ost-av commented 9 months ago

To reproduce, just create a table with 1 record. And run the following code: Transaction method:

  1. Delete everything
  2. Select everything using SelectQuery
  3. We see that the quantity is not 0.
    @Transactional
    public Mono<Void> test(){
        return entityRepository.deleteAll()
                .thenMany(SelectQuery.from(Entity.class, "e").execute(lcClient))
                .count()
                .map(cnt -> cnt) //bug = is not empty
                .then();
    }

SelectExecution sources:

    private Flux<T> executeWithoutPreSelect() {
        SelectMapping mapping = buildSelectMapping();

                // FIXME: there is no context for transactions
        Flux<Map<String, Object>> fromDb = buildFinalSql(mapping, query.where, true, hasJoinMany()).execute().fetch().all();
        return Flux.create((Consumer<FluxSink<T>>)sink -> {
            RowHandler handler = new RowHandler(mapping, sink);
            fromDb.doOnComplete(handler::handleEnd).subscribe(handler::handleRow, sink::error);
        });
    }
ost-av commented 9 months ago

upd. presumably it's enough to add .contextWrite(sink.contextView()) before .doOnComplete