Skip to content

Commit

Permalink
Fixed Namespace inheritance from the parent Workflow when a Child Wor…
Browse files Browse the repository at this point in the history
…kflow options are created (#415)
  • Loading branch information
roxblnfk authored Apr 10, 2024
1 parent 0ae7ac6 commit 3c5b238
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Internal/Workflow/WorkflowContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,7 @@ public function newUntypedChildWorkflowStub(
string $type,
ChildWorkflowOptions $options = null,
): ChildWorkflowStubInterface {
$options ??= (new ChildWorkflowOptions())
->withNamespace($this->getInfo()->namespace);
$options ??= new ChildWorkflowOptions();

return new ChildWorkflowStub($this->services->marshaller, $type, $options, $this->getHeader());
}
Expand Down
8 changes: 8 additions & 0 deletions src/Workflow/ChildWorkflowOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Temporal\Internal\Support\DateInterval;
use Temporal\Internal\Support\Options;
use Temporal\Worker\WorkerFactoryInterface;
use Temporal\Workflow;

/**
* @psalm-import-type DateIntervalValue from DateInterval
Expand Down Expand Up @@ -165,6 +166,13 @@ public function __construct()
$this->workflowRunTimeout = CarbonInterval::seconds(0);
$this->workflowTaskTimeout = CarbonInterval::seconds(0);

try {
// Inherit namespace from the current Workflow if possible
$this->namespace = Workflow::getInfo()->namespace;
} catch (\Throwable) {
// Do nothing
}

parent::__construct();
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Fixtures/data/Test_ExecuteChildWorkflowNamespaced.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
2021/01/12 15:29:11 DEBUG [{"command":"StartWorkflow","options":{"info":{"WorkflowExecution":{"ID":"ab0dac3f-df7e-44ea-9964-c67aadfffcbf","RunID":"eede8d74-cabb-4c49-bd0d-b87f14306d33"},"WorkflowType":{"Name":"WithChildWorkflow"},"TaskQueueName":"default","WorkflowExecutionTimeout":315360000000000000,"WorkflowRunTimeout":315360000000000000,"WorkflowTaskTimeout":0,"Namespace":"foobar","Attempt":1,"CronSchedule":"","ContinuedExecutionRunID":"","ParentWorkflowNamespace":"","ParentWorkflowExecution":null,"Memo":null,"SearchAttributes":null,"BinaryChecksum":"0843e92328c0fb62c02212ed103edb4d"}},"payloads":"CicKFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SDSJIZWxsbyBXb3JsZCI="}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.7617832Z"}
2021/01/12 15:29:11 DEBUG [{"id":9001,"command":"ExecuteChildWorkflow","options":{"name":"SimpleWorkflow","options":{"Namespace":"foobar","WorkflowID":null,"TaskQueueName":"default","WorkflowExecutionTimeout":0,"WorkflowRunTimeout":0,"WorkflowTaskTimeout":0,"WaitForCancellation":false,"WorkflowIDReusePolicy":2,"RetryPolicy":null,"CronSchedule":null,"ParentClosePolicy":1,"Memo":null,"SearchAttributes":null}},"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJjaGlsZCBIZWxsbyBXb3JsZCI=","header":""},{"id":9002,"command":"GetChildWorkflowExecution","options":{"id":9001},"payloads":"","header":""},{"payloads":"ChkKFwoIZW5jb2RpbmcSC2JpbmFyeS9udWxs"}] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9002,"payloads":"CngKFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SXnsiSUQiOiJlZWRlOGQ3NC1jYWJiLTRjNDktYmQwZC1iODdmMTQzMDZkMzNfMSIsIlJ1bklEIjoiNDMyMDgxZGItZGQyZS00ODY1LTk0MDctZTNjM2Y5NWYyZTc0In0="}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.8333619Z"}
2021/01/12 15:29:11 DEBUG [{"command":"StartWorkflow","options":{"info":{"WorkflowExecution":{"ID":"eede8d74-cabb-4c49-bd0d-b87f14306d33_1","RunID":"432081db-dd2e-4865-9407-e3c3f95f2e74"},"WorkflowType":{"Name":"SimpleWorkflow"},"TaskQueueName":"default","WorkflowExecutionTimeout":0,"WorkflowRunTimeout":0,"WorkflowTaskTimeout":0,"Namespace":"foobar","Attempt":1,"CronSchedule":"","ContinuedExecutionRunID":"","ParentWorkflowNamespace":"default","ParentWorkflowExecution":{"ID":"ab0dac3f-df7e-44ea-9964-c67aadfffcbf","RunID":"eede8d74-cabb-4c49-bd0d-b87f14306d33"},"Memo":null,"SearchAttributes":null,"BinaryChecksum":"0843e92328c0fb62c02212ed103edb4d"}},"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJjaGlsZCBIZWxsbyBXb3JsZCI=","header":""}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.8345687Z"}
2021/01/12 15:29:11 DEBUG [] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9003,"command":"ExecuteActivity","options":{"name":"SimpleActivity.echo","options":{"TaskQueueName":null,"ScheduleToCloseTimeout":0,"ScheduleToStartTimeout":0,"StartToCloseTimeout":5000000000,"HeartbeatTimeout":0,"WaitForCancellation":false,"ActivityID":"","RetryPolicy":{"initial_interval":null,"backoff_coefficient":2,"maximum_interval":null,"maximum_attempts":2,"non_retryable_error_types":[]}}},"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJjaGlsZCBIZWxsbyBXb3JsZCI=","header":""},{"payloads":"ChkKFwoIZW5jb2RpbmcSC2JpbmFyeS9udWxs"}] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9003,"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJDSElMRCBIRUxMTyBXT1JMRCI="}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.8915616Z"}
2021/01/12 15:29:11 DEBUG [{"id":9004,"command":"CompleteWorkflow","options":{},"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJDSElMRCBIRUxMTyBXT1JMRCI=","header":""}] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9004,"payloads":"CiUKFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SCyJjb21wbGV0ZWQi"},{"command":"DestroyWorkflow","options":{"runId":"432081db-dd2e-4865-9407-e3c3f95f2e74"}}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.8915616Z","replay":true}
2021/01/12 15:29:11 DEBUG [{"payloads":"ChkKFwoIZW5jb2RpbmcSC2JpbmFyeS9udWxs"}] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9001,"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJDSElMRCBIRUxMTyBXT1JMRCI="}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.9169058Z"}
2021/01/12 15:29:11 DEBUG [{"id":9005,"command":"CompleteWorkflow","options":{},"payloads":"CjQKFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SGiJDaGlsZDogQ0hJTEQgSEVMTE8gV09STEQi","header":""}] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9005,"payloads":"CiUKFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SCyJjb21wbGV0ZWQi"},{"command":"DestroyWorkflow","options":{"runId":"eede8d74-cabb-4c49-bd0d-b87f14306d33"}}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.9169058Z","replay":true}
2021/01/12 15:29:11 DEBUG [{"payloads":"ChkKFwoIZW5jb2RpbmcSC2JpbmFyeS9udWxs"}] {"receive": true}
10 changes: 10 additions & 0 deletions tests/Functional/WorkflowTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ public function testExecuteChildWorkflow()
$worker->run($this, Splitter::create('Test_ExecuteChildWorkflow.log')->getQueue());
}

/**
* Namespace must be inherited by default
*/
public function testExecuteChildWorkflowNamespaced(): void
{
$worker = WorkerMock::createMock();

$worker->run($this, Splitter::create('Test_ExecuteChildWorkflowNamespaced.log')->getQueue());
}

public function testRuntimeSignal()
{
$worker = WorkerMock::createMock();
Expand Down

0 comments on commit 3c5b238

Please sign in to comment.