Skip to content

Commit 7aaf633

Browse files
authored
fix: return false outside workflow code,
1 parent dab1ab6 commit 7aaf633

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowInternal.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,8 @@ static void assertNotReadOnly(String action) {
962962
}
963963

964964
public static boolean isSubjectToReplay() {
965-
return getRootWorkflowContext().isSubjectToReplay();
965+
Optional<WorkflowThread> thread = DeterministicRunnerImpl.currentThreadInternalIfPresent();
966+
return thread.isPresent() && getRootWorkflowContext().isSubjectToReplay();
966967
}
967968

968969
static void assertNotInUpdateHandler(String message) {

‎temporal-sdk/src/main/java/io/temporal/workflow/unsafe/WorkflowUnsafe.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ public static boolean isReplaying() {
5656
* functions run once against the current state and are never re-executed, so they are not subject
5757
* to replay even while {@link #isReplaying()} reports true.
5858
*
59-
* <p>Must be called from Workflow code.
60-
*
61-
* @return true if the calling context is re-executed on replay
59+
* @return true if the calling context is re-executed on replay. This method always returns false
60+
* if called from a non workflow thread.
6261
*/
6362
@Experimental
6463
public static boolean isSubjectToReplay() {

‎temporal-sdk/src/test/java/io/temporal/workflow/WorkflowUnsafeSubjectToReplayTest.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.temporal.workflow;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
45

56
import io.temporal.client.WorkflowClient;
67
import io.temporal.client.WorkflowStub;
@@ -79,6 +80,11 @@ public void isSubjectToReplay() {
7980
assertEquals(expected, calls);
8081
}
8182

83+
@Test
84+
public void isSubjectToReplayOffWorkflowThread() {
85+
assertFalse(WorkflowUnsafe.isSubjectToReplay());
86+
}
87+
8288
private static void record(String name) {
8389
calls.put(name, WorkflowUnsafe.isSubjectToReplay());
8490
}

0 commit comments

Comments
 (0)