From c52584df175f9e8ea025a6d0fb9c7644efadf3e8 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 13:39:37 +0530 Subject: [PATCH] Coerce only single model rules, never unions Coercing a union-typed value into a Document reached a branch that had never run: the single-value path hands rule['type'] to output(), which takes a string, so a user's hashOptions returned a 500 instead of its algo. Only the array branch resolves a model per item. Restrict the coercion to array rules naming one model, and leave the single-value path as it was. --- src/Appwrite/Utopia/Response.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 2ee1d508a6..c5ef65ceda 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -563,7 +563,8 @@ class Response extends SwooleResponse foreach ($data[$key] as $index => $item) { // A model-typed rule handed a raw array would otherwise ship every key it carries. - if (\is_array($item) && (\is_array($rule['type']) || self::hasModel($rule['type']))) { + // Union types are left alone: their branch resolves a model per item. + if (\is_array($item) && !\is_array($rule['type']) && self::hasModel($rule['type'])) { $item = new Document($item); } @@ -602,10 +603,6 @@ class Response extends SwooleResponse } } } else { - if (\is_array($data[$key]) && (\is_array($rule['type']) || self::hasModel($rule['type']))) { - $data[$key] = new Document($data[$key]); - } - if ($data[$key] instanceof Document) { $data[$key] = $this->output($data[$key], $rule['type']); }