Skip to content

Commit 2c3cc09

Browse files
abnegateclaude
andcommitted
(fix): skip structure validation for internal metadata document updates
Metadata documents contain JSON-filtered fields (like attributes and indexes) that are stored as strings but decoded to arrays of Document objects. The Structure validator validates against the raw schema type (string) but receives the decoded value (array), causing false validation failures. Wraps all updateDocument(self::METADATA, ...) calls in skipValidation() since metadata document structure is controlled internally. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 89e7afc commit 2c3cc09

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/Database/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,7 @@ private function updateMetadata(
22482248
try {
22492249
if ($collection->getId() !== self::METADATA) {
22502250
$this->withRetries(
2251-
fn () => $this->silent(fn () => $this->updateDocument(self::METADATA, $collection->getId(), $collection))
2251+
fn () => $this->skipValidation(fn () => $this->silent(fn () => $this->updateDocument(self::METADATA, $collection->getId(), $collection)))
22522252
);
22532253
}
22542254
} catch (Throwable $e) {

src/Database/Traits/Collections.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public function updateCollection(string $id, array $permissions, bool $documentS
256256
->setAttribute('$permissions', $permissions)
257257
->setAttribute('documentSecurity', $documentSecurity);
258258

259-
$collection = $this->silent(fn () => $this->updateDocument(self::METADATA, $collection->getId(), $collection));
259+
$collection = $this->skipValidation(fn () => $this->silent(fn () => $this->updateDocument(self::METADATA, $collection->getId(), $collection)));
260260

261261
$this->trigger(Event::CollectionUpdate, $collection);
262262

src/Database/Traits/Relationships.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,12 @@ public function createRelationship(
294294
$this->silent(function () use ($collection, $relatedCollection, $type, $twoWay, $id, $twoWayKey, $junctionCollection, $created) {
295295
$indexesCreated = [];
296296
try {
297-
$this->withRetries(function () use ($collection, $relatedCollection) {
298-
$this->withTransaction(function () use ($collection, $relatedCollection) {
299-
$this->updateDocument(self::METADATA, $collection->getId(), $collection);
300-
$this->updateDocument(self::METADATA, $relatedCollection->getId(), $relatedCollection);
297+
$this->skipValidation(function () use ($collection, $relatedCollection) {
298+
$this->withRetries(function () use ($collection, $relatedCollection) {
299+
$this->withTransaction(function () use ($collection, $relatedCollection) {
300+
$this->updateDocument(self::METADATA, $collection->getId(), $collection);
301+
$this->updateDocument(self::METADATA, $relatedCollection->getId(), $relatedCollection);
302+
});
301303
});
302304
});
303305
} catch (Throwable $e) {
@@ -369,7 +371,7 @@ public function createRelationship(
369371
}
370372

371373
try {
372-
$this->withTransaction(function () use ($collection, $relatedCollection, $id, $twoWayKey) {
374+
$this->skipValidation(fn () => $this->withTransaction(function () use ($collection, $relatedCollection, $id, $twoWayKey) {
373375
/** @var array<Document> $attributes */
374376
$attributes = $collection->getAttribute('attributes', []);
375377
$collection->setAttribute('attributes', array_filter($attributes, fn (Document $attr) => $attr->getId() !== $id));
@@ -379,7 +381,7 @@ public function createRelationship(
379381
$relatedAttributes = $relatedCollection->getAttribute('attributes', []);
380382
$relatedCollection->setAttribute('attributes', array_filter($relatedAttributes, fn (Document $attr) => $attr->getId() !== $twoWayKey));
381383
$this->updateDocument(self::METADATA, $relatedCollection->getId(), $relatedCollection);
382-
});
384+
}));
383385
} catch (Throwable $cleanupError) {
384386
Console::error("Failed to cleanup metadata for relationship '{$id}': ".$cleanupError->getMessage());
385387
}
@@ -910,11 +912,13 @@ public function deleteRelationship(string $collection, string $id): bool
910912
}
911913

912914
try {
913-
$this->withRetries(function () use ($collection, $relatedCollection) {
914-
$this->silent(function () use ($collection, $relatedCollection) {
915-
$this->withTransaction(function () use ($collection, $relatedCollection) {
916-
$this->updateDocument(self::METADATA, $collection->getId(), $collection);
917-
$this->updateDocument(self::METADATA, $relatedCollection->getId(), $relatedCollection);
915+
$this->skipValidation(function () use ($collection, $relatedCollection) {
916+
$this->withRetries(function () use ($collection, $relatedCollection) {
917+
$this->silent(function () use ($collection, $relatedCollection) {
918+
$this->withTransaction(function () use ($collection, $relatedCollection) {
919+
$this->updateDocument(self::METADATA, $collection->getId(), $collection);
920+
$this->updateDocument(self::METADATA, $relatedCollection->getId(), $relatedCollection);
921+
});
918922
});
919923
});
920924
});

0 commit comments

Comments
 (0)