Skip to content

Commit

Permalink
Fix @transactional support on suspending function
Browse files Browse the repository at this point in the history
With this commit, @transactional on suspending functions
returning a value now commits the transaction properly.

Closes gh-25998
  • Loading branch information
sdeleuze committed Nov 9, 2020
1 parent 6bb3ad7 commit 1f13516
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,8 @@ public Object invokeWithinTransaction(Method method, @Nullable Class<?> targetCl

String joinpointIdentification = methodIdentification(method, targetClass, txAttr);

// Optimize for Mono
if (Mono.class.isAssignableFrom(method.getReturnType())) {
// For Mono and suspending functions not returning kotlinx.coroutines.flow.Flow
if (Mono.class.isAssignableFrom(method.getReturnType()) || (KotlinDetector.isSuspendingFunction(method) && !COROUTINES_FLOW_CLASS_NAME.equals(new MethodParameter(method, -1).getParameterType().getName()))) {
return TransactionContextManager.currentContext().flatMap(context ->
createTransactionIfNecessary(rtm, txAttr, joinpointIdentification).flatMap(it -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.springframework.transaction.annotation
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.springframework.aop.framework.ProxyFactory
import org.springframework.transaction.interceptor.TransactionInterceptor
Expand Down Expand Up @@ -64,7 +63,6 @@ class CoroutinesAnnotationTransactionInterceptorTests {
}

@Test
@Disabled("Currently fails due to gh-25998")
fun suspendingValueSuccess() {
val proxyFactory = ProxyFactory()
proxyFactory.setTarget(TestWithCoroutines())
Expand Down

0 comments on commit 1f13516

Please sign in to comment.