You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(registeredscript): resolve version diff detection issue (#52)
This fixes an issue where RegisteredScript would always detect a version
diff even when the version hadn't changed, causing unnecessary replacements.
Root cause: Pulumi's struct embedding doesn't properly deserialize the
version field into the embedded RegisteredScriptResourceArgs struct,
causing req.State.Version to be empty during Diff comparison.
Changes:
- Made version field optional in struct tag for backwards compatibility
with existing state (Create still validates version is provided)
- Updated Diff method to only compare version when both state and inputs
have non-empty values
Also updates ISSUES-TO-FIX.md with resolution status for Issues 1, 2, and 4,
and documents two new issues discovered during testing (Asset variants
parsing and CollectionItem slug uniqueness).
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
**Problem:** When Pulumi detects a diff in RegisteredScript (e.g., version change), it calls the Update method which uses `PutRegisteredScript`. The Webflow API returns 404.
10
12
11
-
**Error:**
12
-
```
13
-
error: failed to update registered script: not found: the Webflow site or robots.txt configuration does not exist.
14
-
```
13
+
**Root Cause:** Webflow API v2 does not support PATCH/PUT for registered scripts. Only GET (list), POST (create), and DELETE are available.
15
14
16
-
**Investigation needed:**
17
-
- Check if Webflow's API supports updating registered scripts at all
18
-
- Verify the PUT endpoint URL is correct
19
-
- May need to implement as delete+recreate instead of update
15
+
**Solution:** Changed all field changes to trigger replacement (delete + recreate) instead of in-place update. All changes now use `p.UpdateReplace` in the Diff method with `DeleteBeforeReplace = true`.
20
16
21
17
---
22
18
23
19
## 2. SiteCustomCode Script ID Format
24
20
21
+
**Status:** ✅ RESOLVED (was blocked by Issue 1 & 4)
22
+
25
23
**File:**`provider/sitecustomcode_resource.go`
26
24
27
25
**Problem:** When creating SiteCustomCode with a registered script, the API returns "invalid id and version".
28
26
29
-
**Error:**
30
-
```
31
-
error: failed to create site custom code: bad request: {"message":"Bad Request: At least one script contained an invalid id and version","code":"bad_request"}
32
-
```
27
+
**Root Cause:** This issue was caused by Issues 1 and 4. When RegisteredScript had problems (update 404 errors, false version diffs triggering unnecessary replacements), the script ID would become unknown during replacement, causing SiteCustomCode validation to fail.
33
28
34
-
**Investigation needed:**
35
-
- Verify what format the `id` field expects (displayName vs script ID)
36
-
- Check if version must match exactly what's registered
37
-
- Test with hardcoded values to isolate the issue
38
-
- May be blocked until RegisteredScript issues are resolved
29
+
**Resolution:** After fixing Issues 1 and 4, SiteCustomCode works correctly. The script ID format (human-readable string derived from displayName) is correct as documented.
**Problem:** Even after refresh, Pulumi keeps detecting a version diff on RegisteredScript, triggering unnecessary updates.
65
60
66
-
**Root cause:** Webflow's list scripts API doesn't return the `version` field. The Read method preserves version from state, but something causes Diff to still see a change.
61
+
**Root Causes:**
62
+
63
+
1. All changes should trigger replacement, not update (fixed in PR #51)
64
+
2. Pulumi's struct embedding doesn't properly deserialize the version field into the embedded `RegisteredScriptResourceArgs` struct, causing `req.State.Version` to be empty when compared
65
+
66
+
**Solution:**
67
+
68
+
- Changed version field back to optional in struct tag (for backwards compatibility with existing state)
69
+
- Updated Diff method to only compare version if both state and inputs have non-empty values
70
+
- Create method still validates that version is provided for new resources
71
+
72
+
---
73
+
74
+
## 5. Asset Variants Parsing Error (NEW)
75
+
76
+
**Status:** ❌ NOT YET FIXED
67
77
68
-
**Workaround applied:** Made `version` optional in schema (line 43), but this may have side effects.
78
+
**File:**`provider/asset.go`
79
+
80
+
**Problem:** The Asset resource fails to read with a JSON parsing error.
81
+
82
+
**Error:**
83
+
```
84
+
error: Preview failed: failed to read asset: failed to parse response: json: cannot unmarshal array into Go struct field AssetResponse.variants of type map[string]provider.AssetVariant
85
+
```
86
+
87
+
**Root Cause:** The Webflow API returns `variants` as an array, but the Go struct expects a map.
69
88
70
89
**Investigation needed:**
71
-
- Debug what values Diff receives for `req.State.Version` vs `req.Inputs.Version`
72
-
- May need to adjust how Read populates the response
73
-
- Consider if version should trigger replacement instead of update
90
+
91
+
- Update the `AssetResponse` struct to handle `variants` as an array
92
+
- Check Webflow API documentation for the correct variants format
93
+
94
+
---
95
+
96
+
## 6. CollectionItem Slug Uniqueness Error (NEW)
97
+
98
+
**Status:** ❌ NOT YET FIXED
99
+
100
+
**File:**`provider/collectionitem_resource.go`
101
+
102
+
**Problem:** When updating a CollectionItem, the API rejects the request with a slug uniqueness error even when the slug hasn't changed.
103
+
104
+
**Error:**
105
+
106
+
```text
107
+
error: failed to update collection item: bad request: {"message":"Validation Error","code":"validation_error","details":[{"param":"slug","description":"Unique value is already in database: 'test-blog-post'"}]}
108
+
```
109
+
110
+
**Root Cause:** The update request includes the unchanged slug, and Webflow rejects it because the slug already exists (for the same item).
111
+
112
+
**Fix needed:** Exclude unchanged slug from PATCH requests, similar to the fix applied for Collection resource.
74
113
75
114
---
76
115
@@ -82,9 +121,10 @@ Test stack is at `/private/tmp/test-webflow` with these working resources:
82
121
- RobotsTxt
83
122
- Collection (with new `collectionId` output)
84
123
- CollectionField
85
-
- CollectionItem
124
+
- CollectionItem (note: has slug update issue)
86
125
- Webhook
87
126
- AssetFolder
88
-
- RegisteredScript (Read works, Update broken)
127
+
- RegisteredScript ✅ (fully working)
128
+
- SiteCustomCode ✅ (fully working)
89
129
90
-
SiteCustomCode is defined but not yet created due to above issues.
130
+
Asset is temporarily commented out due to variants parsing bug.
0 commit comments