Skip to content

Commit 142b8dd

Browse files
abnegateclaude
andcommitted
fix: Cast comparison values by attribute type in updateDocument
Cast individual values to their declared attribute type before comparing with $old, skipping Operator instances. This normalizes types degraded by cache JSON round-trips (e.g. float 1.0 → int 1) without affecting the document that gets persisted. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0380e4a commit 142b8dd

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/Database/Database.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5596,12 +5596,17 @@ public function updateDocument(string $collection, string $id, Document $documen
55965596
$document['$tenant'] = $old->getTenant(); // Make sure user doesn't switch tenant
55975597
}
55985598
$document = new Document($document);
5599-
$document = $this->casting($collection, $document);
56005599

56015600
$relationships = \array_filter($collection->getAttribute('attributes', []), function ($attribute) {
56025601
return $attribute['type'] === Database::VAR_RELATIONSHIP;
56035602
});
56045603

5604+
// Build attribute type map for type-safe comparison
5605+
$attributeTypes = [];
5606+
foreach ($collection->getAttribute('attributes', []) as $attr) {
5607+
$attributeTypes[$attr['$id'] ?? ''] = $attr['type'] ?? '';
5608+
}
5609+
56055610
$shouldUpdate = false;
56065611

56075612
if ($collection->getId() !== self::METADATA) {
@@ -5699,6 +5704,18 @@ public function updateDocument(string $collection, string $id, Document $documen
56995704

57005705
$oldValue = $old->getAttribute($key);
57015706

5707+
// Cast value to attribute type for consistent comparison
5708+
// (e.g. cache JSON round-trip turns float 1.0 into int 1)
5709+
$attrType = $attributeTypes[$key] ?? null;
5710+
if ($attrType !== null && !\is_null($value) && !($value instanceof Operator)) {
5711+
$value = match ($attrType) {
5712+
self::VAR_FLOAT => (float)$value,
5713+
self::VAR_INTEGER => (int)$value,
5714+
self::VAR_BOOLEAN => (bool)$value,
5715+
default => $value,
5716+
};
5717+
}
5718+
57025719
// If values are not equal we need to update document.
57035720
if ($value !== $oldValue) {
57045721
$shouldUpdate = true;

0 commit comments

Comments
 (0)