Skip to content

Commit e7edc9c

Browse files
abnegateclaude
andcommitted
fix: allow int|string|null in Sequence validator and use loose comparison
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9aa4206 commit e7edc9c

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/Database/Database.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6055,7 +6055,7 @@ public function updateDocument(string $collection, string $id, Document $documen
60556055
$document['$createdAt'] = ($createdAt === null || !$this->preserveDates) ? $old->getCreatedAt() : $createdAt;
60566056

60576057
if ($this->adapter->getSharedTables()) {
6058-
$document['$tenant'] = $old->getAttribute('$tenant'); // Make sure user doesn't switch tenant
6058+
$document['$tenant'] = $old->getTenant(); // Make sure user doesn't switch tenant
60596059
}
60606060
$document = new Document($document);
60616061

@@ -6160,8 +6160,7 @@ public function updateDocument(string $collection, string $id, Document $documen
61606160

61616161
$oldValue = $old->getAttribute($key);
61626162

6163-
// If values are not equal we need to update document.
6164-
if ($value !== $oldValue) {
6163+
if ($value != $oldValue) {
61656164
$shouldUpdate = true;
61666165
break;
61676166
}

src/Database/Validator/Sequence.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ public function isValid($value): bool
4141
return false;
4242
}
4343

44-
if (!\is_string($value)) {
44+
if ($value === null) {
45+
return true;
46+
}
47+
48+
if (!\is_string($value) && !\is_int($value)) {
4549
return false;
4650
}
4751

4852
switch ($this->idAttributeType) {
49-
case Database::VAR_UUID7: //UUID7
50-
return preg_match('/^[a-f0-9]{8}-[a-f0-9]{4}-7[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i', $value) === 1;
53+
case Database::VAR_UUID7:
54+
return \is_string($value) && preg_match('/^[a-f0-9]{8}-[a-f0-9]{4}-7[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i', $value) === 1;
5155
case Database::VAR_INTEGER:
5256
$start = ($this->primary) ? 1 : 0;
5357
$validator = new Range($start, Database::MAX_BIG_INT, Database::VAR_INTEGER);

src/Database/Validator/Structure.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,6 @@ protected function checkForInvalidAttributeValues(array $structure, array $keys)
340340

341341
switch ($type) {
342342
case Database::VAR_ID:
343-
if ($attribute['$id'] === '$tenant') {
344-
break;
345-
}
346343
$validators[] = new Sequence($this->idAttributeType, $attribute['$id'] === '$sequence');
347344
break;
348345

0 commit comments

Comments
 (0)