Skip to content

Commit 5965754

Browse files
authored
fix: Force upload for non-ACTIVE functions to prevent GCFv2 update failure (#9456)
* Fix: Force upload for non-ACTIVE functions to prevent GCFv2 update failure When a GCFv2 function is in a FAILED state but the local source code hasn't changed, the CLI previously skipped the source upload. This caused the subsequent update operation to fail with 'Precondition failed' because it lacked the required storage source information. This change ensures that source upload is only skipped if the existing function is in an ACTIVE state, forcing a re-upload and allowing repair of FAILED functions. * Add changelog entry for GCFv2 precondition fix * Refactor: Remove duplicate test case in deploy.spec.ts
1 parent 518357b commit 5965754

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- [Added] support for new google-genai plugin during `init genkit` (#8957)
22
- Updated to v2.17.1 of the Data Connect emulator, which fixes an admin SDK bug for operation without argument #9449 (#9454).
3+
- Fixed "Precondition failed" error when updating GCFv2 functions in a FAILED state without code changes.

src/deploy/functions/deploy.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ describe("deploy", () => {
6666
haveBackend = backend.of(endpoint1InHaveBackend, endpoint2InHaveBackend);
6767
});
6868

69-
it("should skip if all endpoints are identical", () => {
69+
it("should skip if all endpoints are identical and ACTIVE", () => {
7070
endpoint1InWantBackend.hash = "1";
7171
endpoint2InWantBackend.hash = "2";
7272
endpoint1InHaveBackend.hash = endpoint1InWantBackend.hash;
7373
endpoint2InHaveBackend.hash = endpoint2InWantBackend.hash;
74+
endpoint1InHaveBackend.state = "ACTIVE";
75+
endpoint2InHaveBackend.state = "ACTIVE";
7476

7577
// Execute
7678
const result = deploy.shouldUploadBeSkipped(CONTEXT, wantBackend, haveBackend);
@@ -140,6 +142,19 @@ describe("deploy", () => {
140142
// Expect
141143
expect(result).to.be.false;
142144
});
145+
146+
it("should not skip if state is not ACTIVE", () => {
147+
endpoint1InWantBackend.hash = "1";
148+
endpoint2InWantBackend.hash = "2";
149+
endpoint1InHaveBackend.hash = endpoint1InWantBackend.hash;
150+
endpoint2InHaveBackend.hash = endpoint2InWantBackend.hash;
151+
endpoint1InHaveBackend.state = "ACTIVE";
152+
endpoint2InHaveBackend.state = "FAILED";
153+
154+
const result = deploy.shouldUploadBeSkipped(CONTEXT, wantBackend, haveBackend);
155+
156+
expect(result).to.be.false;
157+
});
143158
});
144159

145160
describe("uploadSourceV2", () => {

src/deploy/functions/deploy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ export function shouldUploadBeSkipped(
221221
if (!haveEndpoint) {
222222
return false;
223223
}
224-
return haveEndpoint.hash && wantEndpoint.hash && haveEndpoint.hash === wantEndpoint.hash;
224+
return (
225+
haveEndpoint.hash &&
226+
wantEndpoint.hash &&
227+
haveEndpoint.hash === wantEndpoint.hash &&
228+
haveEndpoint.state === "ACTIVE"
229+
);
225230
});
226231
}

0 commit comments

Comments
 (0)