Fix @Transactional support on suspending function
With this commit, @Transactional on suspending functions returning a value now commits the transaction properly. Closes gh-25998
This commit is contained in:
@@ -875,8 +875,8 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
||||
|
||||
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 {
|
||||
|
||||
@@ -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
|
||||
@@ -64,7 +63,6 @@ class CoroutinesAnnotationTransactionInterceptorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("Currently fails due to gh-25998")
|
||||
fun suspendingValueSuccess() {
|
||||
val proxyFactory = ProxyFactory()
|
||||
proxyFactory.setTarget(TestWithCoroutines())
|
||||
|
||||
Reference in New Issue
Block a user