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

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

Open
ost-av opened this issue Jan 22, 2024 · 1 comment

Comments

@ost-av
Copy link

ost-av commented Jan 22, 2024

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
Copy link
Author

ost-av commented Jan 22, 2024

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

ost-av added a commit to ost-av/lc-spring-data-r2dbc that referenced this issue Jan 22, 2024
…ntext to the fromDb variable, which is why transactions do not work.

Fixes lecousin#28
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

No branches or pull requests

1 participant