Skip to content

fix: return fresh devKey document from update endpoint#11920

Open
yogeshwaran-c wants to merge 1 commit intoappwrite:1.9.xfrom
yogeshwaran-c:fix/projects-devkey-update-return-value
Open

fix: return fresh devKey document from update endpoint#11920
yogeshwaran-c wants to merge 1 commit intoappwrite:1.9.xfrom
yogeshwaran-c:fix/projects-devkey-update-return-value

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

Summary

PUT /v1/projects/:projectId/dev-keys/:keyId (Projects/Http/DevKeys/Update.php) currently mutates the in-memory $key via setAttribute('name')/setAttribute('expire') and issues a sparse updateDocument(), but does not capture the updated document that updateDocument() returns. The response is then rendered from the pre-update $key, so the client receives a stale $updatedAt (and any other server-maintained fields like internal sequences would be out of date as well).

This assigns the updateDocument() return back to $key and drops the now-redundant setAttribute chain, matching the pattern already used by Project/Http/Project/Keys/Update.php, every Project/Http/Project/Platforms/*/Update.php, and the cloud/account variants that were aligned during #11465.

Before

$key
    ->setAttribute('name', $name)
    ->setAttribute('expire', $expire);

$dbForPlatform->updateDocument('devKeys', $key->getId(), new Document(['name' => $name, 'expire' => $expire]));

After

$key = $dbForPlatform->updateDocument('devKeys', $key->getId(), new Document(['name' => $name, 'expire' => $expire]));

Test plan

  • PUT /v1/projects/:projectId/dev-keys/:keyId returns a $updatedAt that reflects the write (no longer equal to $createdAt / last value from getDocument).
  • Response name and expire still reflect the request payload.
  • $dbForPlatform->purgeCachedDocument('projects', $project->getId()) is still called after the update.

The devKey update action mutated the in-memory $key via setAttribute
and then wrote a sparse Document, but did not capture the return of
updateDocument. The response therefore returned a stale $updatedAt
taken from the pre-update fetch.

Drop the redundant setAttribute chain and reassign $key from the
updateDocument return, matching the pattern used by sibling Update
actions (e.g. Project/Keys/Update, Project/Platforms/*/Update).
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 16, 2026

Greptile Summary

This PR fixes a stale-response bug in the dev key update endpoint where the response was rendered from the pre-update in-memory document rather than the freshly persisted one. The fix assigns the updateDocument() return value back to $key, aligning it with the established pattern used by Project/Http/Project/Keys/Update.php and other update endpoints in the codebase.

Confidence Score: 5/5

Safe to merge — single-line fix with no side effects, corrects a response-staleness bug.

The change is minimal, correct, and consistent with the established pattern across the codebase. No P0 or P1 issues found; all remaining behaviour (cache purge, response rendering) is preserved.

No files require special attention.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php Captures the return value of updateDocument() back into $key, ensuring the response reflects the fresh server-side document (including updated $updatedAt). Redundant setAttribute calls removed. Change is correct and consistent with the pattern in Project/Http/Project/Keys/Update.php.

Reviews (1): Last reviewed commit: "fix: capture updated devKey document to ..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant