Repository navigation
fix: format datetime fields in the response model - #14295
Conversation
Documents built in memory (a synchronous execution, a queued async execution) never pass through the database datetime filter, so they were returned, and copied into event payloads, in the database format without a timezone. Response::output() now normalises every TYPE_DATETIME rule to ISO 8601 with offset.
These calls only existed to give in-memory values the documented format in API responses and event payloads, which Response::output() now guarantees. Comparisons, email link parameters and cookie-only values keep their formatTz.
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
The change centralizes datetime output formatting:
Reviewed commit: d99fdb2 |
🟢 Tier S · Ready to mergeResponse model output now formats database-style datetime strings as ISO 8601, and the account/session/token creation paths no longer pre-format values that are persisted or output through the model. E2E coverage was expanded for execution responses, webhook payloads, and account and user expiry fields.
📂 Walkthrough · 10
Merged |
Security rulesNo new WARNING or ERROR findings from security rules. 32 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Summary
A synchronous function execution (
POST /v1/functions/{functionId}/executionswithasync=false) returns$createdAtand$updatedAtin the database format2026-10-09 10:00:00.123, whileGET /v1/functions/{functionId}/executions/{executionId}returns the documented ISO 8601 format2026-10-09T10:00:00.123+00:00. The queued async response (202) has the same problem. Because theapishutdown hook copies$response->getPayload()into the event, thefunctions.*.executions.*.createwebhook, realtime and function-event payloads carry the raw format too.Root cause:
Executions/Create.phpbuilds the execution as an in-memoryDocumentwithDateTime::now()and outputs it without a database round-trip. Normally the databasedatetimefilter (DateTime::formatTzon decode) produces the timezone format on read, andResponse::output()copies values as-is, ignoringModel::TYPE_DATETIME. Every endpoint that answered with an in-memory datetime needed its own inlineDateTime::formatTz()to look right.Fix:
Response::output()now normalises every rule of typeModel::TYPE_DATETIME(includingarrayrules) toY-m-d\TH:i:s.vPviaDateTime::formatTz(). It only converts strings in the database format (space at offset 10), so it is cheap and idempotent: values already carrying theTseparator,null,''and non-strings are returned unchanged (formatTz('')would otherwise turn an empty value into "now"). It runs insideoutput(), which sets$this->payload, sogetPayload()and every event built from it get the formatted values. It runs after the sensitive-field masking, so masked values stay''.Why not a response filter
src/Appwrite/Utopia/Response/Filters/V16..V24are API-version compatibility shims that only run for clients pinned to an olderX-Appwrite-Response-Format. This is the current contract ofTYPE_DATETIME(documented example2020-10-15T06:38:00.000+00:00) and has to hold for every client and for event payloads, so it belongs in the model output itself.Removed inline calls
app/controllers/api/account.php($createSession, used byPUT /account/sessions/magic-url,PUT /account/sessions/phone,POST /account/sessions/token)expire(new \DateTime($expire))->getTimestamp()is format-agnostic, both strings are in the same default timezone) and the response attribute.app/controllers/api/account.php(PATCH /account/sessions/:sessionId)expire,providerAccessTokenExpiryupdateDocument(the datetime filter encodes either format), then output throughResponse::output()for both the event payload and the response.User::sessionVerify()normalises both sides before comparing.app/controllers/api/account.php(GET /account/sessions/oauth2/:provider/redirect)expirecreateDocument; sessionexpirefeeds the cookie timestamp and the event payload, which goes throughResponse::output(). The endpoint itself redirects.app/controllers/api/account.php(POST /account/tokens/email,POST /account/tokens/phone,POST /account/recovery/otp,POST /account/verifications/phone,POST /account/verifications/email/otp)expirecreateDocument, which is already decoded. Not used in any email/SMS template or URL.src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.phpexpirecreateDocumentresult. Not used in the SMS/email content.src/Appwrite/Platform/Modules/Users/Http/Users/Sessions/Create.phpexpirecreateDocumentresult.src/Appwrite/Platform/Modules/Users/Http/Users/Tokens/Create.phpexpirecreateDocumentresult.Functions/Http/Executions/Create.phpneeded no code change: its in-memoryDateTime::now()values are now formatted by the response.Kept on purpose
Y-m-d H:i:sandY-m-d\TH:i:swould break:app/controllers/general.php:151,app/controllers/shared/api.php(209, 409, 430, 775, 800, 1143),app/controllers/shared/api/auth.php(26, 43-45),app/init/realtime/connection.php:301,app/init/resources/request.php(574, 1143),src/Appwrite/Auth/Key.php(206, 237, 273),src/Appwrite/Auth/Passkey/Challenges.php:61,Account/MFA/Challenges/Update.php:109,Account/Passkeys/Create.php:184,Messaging/Messages/Delete.php:77,Presences/HTTP/Get.php:63,Presences/HTTP/Update.php:145,Storage/Buckets/Files/Preview/Get.php:355,Users/MFA/Challenges/Get.php:72,Tasks/ScheduleMessages.php:77,Workers/Functions.php:411,Utopia/Database/Documents/User.php(123, 149, 173).expirequery parameter of magic URL (POST /account/tokens/magic-url, account.php:2635), recovery (POST /account/recovery, account.php:4154) and email verification (POST /account/verifications/email, account.php:4917).general.php:1665(preview cookie),Account/Sessions/IdToken/Create.php:264. These are not response workarounds, so they are out of scope here.timestamp(app/realtime.php554, 592,Messaging/Adapter/Realtime.php:550): not a response model.Execution/Store.php:858: the ClickHouse execution store normalising what it reads back, the same role the databasedatetimefilter plays.Response/Filters/V16.php(82, 83): version shim output.Follow-ups noticed, not changed here: the functions worker builds the
executions.*.updateevent payload withModel::filter()instead ofResponse::output(), so its datetimes do not get this normalisation.Messaging/Messages/Delete.php:77comparesDateTime::now()(database format) with aformatTzvalue, which is wrong on the same calendar day.Tests
E2E only, extending existing test methods. Assertions use the existing
\DateTime::createFromFormat('Y-m-d\TH:i:s.uP', ...)pattern from the account tests.FunctionsCustomServerTest::testSyncCreateExecution: sync create response$createdAt/$updatedAtare ISO 8601. Fails without the fix.FunctionsCustomServerTest::testListExecutionsWithinCreatedAtWindow: sync (201) and async (202) create responses are ISO 8601. The test's own workaround that converted the 202$createdAtfrom database format before comparing is removed. Fails without the fix.ProjectWebhooks/WebhooksCustomServerTest::testExecutions: thefunctions.*.executions.*.createwebhook payload has ISO 8601$createdAt/$updatedAtequal to the response. Fails without the fix.AccountCustomClientTest::testSessionAlert:POST /account/tokens/emailandPOST /account/sessions/tokenexpire.AccountCustomClientTest::testConvertAnonymousAccountOAuth2:PATCH /account/sessions/currentexpireandproviderAccessTokenExpiry. Fails with the removal and without the central fix.AccountCustomClientTest::testRefreshEmailPasswordSessionalready assertedexpireofPATCH /account/sessions/:sessionId, and fails with the removal and without the central fix.AccountCustomClientTest:testCreatePhone(POST /account/tokens/phone),testCreateEmailVerificationOTP(POST /account/verifications/email/otp),testCreateRecoveryOTP(POST /account/recovery/otp),testRegenerateMFARecoveryCodesRequiresRecentChallenge(POST /account/mfa/challenges);testPhoneVerificationalready had the strict assertion forPOST /account/verifications/phone.AccountCustomServerTest::testCreateTokenWithSessionsKey:POST /account/tokens/emailandPOST /account/recovery/otpwith an API key.UsersBase::testCreateSession,UsersBase::testCreateToken:expire.The assertions for round-tripped values (tokens, challenges, users sessions/tokens) also pass on the base commit, because those responses already came from
createDocument. They guard the removals.Verification
composer lint(Pint) on the changed files: passed.composer analyze(PHPStan,phpstan.neon) on the changed source files: no errors.composer refactor:check(Rector) on the changed tests: no changes.tests/e2e/Services/AccountOK (162 tests, 2953 assertions, 3 skipped),tests/e2e/Services/UsersOK (68 tests, 941 assertions),tests/e2e/Services/ProjectWebhooksOK (82 tests, 8353 assertions),tests/e2e/Services/FunctionsOK (88 tests, 2322 assertions). The warnings come from code this PR does not touch:WebhooksBase::getWebhookSignature()readsdataon an empty request while theexecutions.*.updateassertion is retried, and the functions run reports the expected 500 page printed bytestErrorPagesEmptyBody.Response.phpreverted tomain(removals kept) and the container restarted, these fail as expected:testSyncCreateExecution,testListExecutionsWithinCreatedAtWindow,WebhooksCustomServerTest::testExecutions,testRefreshEmailPasswordSession,testConvertAnonymousAccountOAuth2.Closes #14296