Skip to content

Commit 9f6dd71

Browse files
authored
fix(wrangler): fix r2 data catalog snapshot expiration api call payload (#11764)
1 parent 2a4299d commit 9f6dd71

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Fix R2 Data Catalog snapshot-expiration API field names
6+
7+
The `wrangler r2 bucket catalog snapshot-expiration enable` command was sending incorrect field names
8+
to the Cloudflare API, resulting in a 422 Unprocessable Entity error. This fix updates the API request
9+
body to use the correct field names:
10+
11+
- `olderThanDays` -> `max_snapshot_age` (as duration string, e.g., "30d")
12+
- `retainLast` -> `min_snapshots_to_keep`
13+
14+
The CLI options (`--older-than-days` and `--retain-last`) remain unchanged.

packages/wrangler/src/__tests__/r2/bucket.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,8 +1666,8 @@ describe("r2", () => {
16661666
expect(body).toEqual({
16671667
snapshot_expiration: {
16681668
state: "enabled",
1669-
olderThanDays: 30,
1670-
retainLast: 5,
1669+
max_snapshot_age: "30d",
1670+
min_snapshots_to_keep: 5,
16711671
},
16721672
});
16731673
return HttpResponse.json(
@@ -1717,8 +1717,8 @@ describe("r2", () => {
17171717
expect(body).toEqual({
17181718
snapshot_expiration: {
17191719
state: "enabled",
1720-
olderThanDays: 60,
1721-
retainLast: 10,
1720+
max_snapshot_age: "60d",
1721+
min_snapshots_to_keep: 10,
17221722
},
17231723
});
17241724
return HttpResponse.json(

packages/wrangler/src/r2/helpers/catalog.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ type R2CatalogSnapshotExpirationConfig = {
108108
state: "enabled" | "disabled";
109109

110110
// If undefined, the service will set the default value
111-
olderThanDays?: number;
111+
max_snapshot_age?: string;
112112

113113
// If undefined, the service will set the default value
114-
retainLast?: number;
114+
min_snapshots_to_keep?: number;
115115
};
116116

117117
type R2CatalogSnapshotExpirationResponse = {
@@ -127,8 +127,8 @@ export async function enableR2CatalogSnapshotExpiration(
127127
): Promise<R2CatalogSnapshotExpirationResponse> {
128128
const config: R2CatalogSnapshotExpirationConfig = {
129129
state: "enabled",
130-
olderThanDays: olderThanDays ?? 30,
131-
retainLast: retainLast ?? 5,
130+
max_snapshot_age: `${olderThanDays ?? 30}d`,
131+
min_snapshots_to_keep: retainLast ?? 5,
132132
};
133133

134134
return await fetchResult(

0 commit comments

Comments
 (0)