Skip to content

Commit 805ad2b

Browse files
Workflows: fix getting a workflow when such workflow was not yet created (#7520)
* fix getting a workflow when such workflow was not yet created * Update .changeset/lovely-fireants-roll.md Co-authored-by: Matt Silverlock <[email protected]> * prettify * cleanup --------- Co-authored-by: Matt Silverlock <[email protected]>
1 parent 6915a7a commit 805ad2b

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

.changeset/lovely-fireants-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/workflows-shared": patch
3+
---
4+
5+
Fixed a bug in local development where fetching a Workflow instance by ID would return a Workflow status, even if that instance did not exist. This only impacted the `get()` method on the Worker bindings.

fixtures/import-npm/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/workflow/tests/index.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,15 @@ describe("Workflows", () => {
8383
output: [],
8484
});
8585
});
86+
87+
it("fails getting a workflow without creating it first", async ({
88+
expect,
89+
}) => {
90+
await expect(
91+
fetchJson(`http://${ip}:${port}/status?workflowName=anotherTest`)
92+
).resolves.toMatchObject({
93+
message: "instance.not_found",
94+
name: "Error",
95+
});
96+
});
8697
});

packages/workflows-shared/src/engine.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ export class Engine extends DurableObject<Env> {
142142
_accountId: number,
143143
_instanceId: string
144144
): Promise<InstanceStatus> {
145+
if (this.accountId === undefined) {
146+
throw new Error("stub not initialized");
147+
}
148+
145149
const res = await this.ctx.storage.get<InstanceStatus>(ENGINE_STATUS_KEY);
146150

147151
// NOTE(lduarte): if status don't exist, means that engine is running for the first time, so we assume queued

0 commit comments

Comments
 (0)