Skip to content

Commit 49e2dea

Browse files
abnegateclaude
andcommitted
(fix): use loose comparison for tenant checks and fix PHPStan return type
Tenant values from PDO/MongoDB are cast to strings, while adapter stores them as integers. Strict comparison (!==) always mismatches, breaking all shared-tables operations. Also fix getTenantFilters() PHPDoc to include null in inner array type. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c481610 commit 49e2dea

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/Database/Adapter/Mongo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2430,7 +2430,7 @@ public function getSizeOfCollectionOnDisk(string $collection): int
24302430

24312431
/**
24322432
* @param array<int|string> $tenants
2433-
* @return int|string|null|array<string, array<int|string>>
2433+
* @return int|string|null|array<string, array<int|string|null>>
24342434
*/
24352435
public function getTenantFilters(
24362436
string $collection,

src/Database/Traits/Collections.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function updateCollection(string $id, array $permissions, bool $documentS
247247

248248
if (
249249
$this->adapter->getSharedTables()
250-
&& $collection->getTenant() !== $this->adapter->getTenant()
250+
&& $collection->getTenant() != $this->adapter->getTenant()
251251
) {
252252
throw new NotFoundException('Collection not found');
253253
}
@@ -279,7 +279,7 @@ public function getCollection(string $id): Document
279279
$id !== self::METADATA
280280
&& $this->adapter->getSharedTables()
281281
&& $collection->getTenant() !== null
282-
&& $collection->getTenant() !== $this->adapter->getTenant()
282+
&& $collection->getTenant() != $this->adapter->getTenant()
283283
) {
284284
return new Document();
285285
}
@@ -326,7 +326,7 @@ public function getSizeOfCollection(string $collection): int
326326
throw new NotFoundException('Collection not found');
327327
}
328328

329-
if ($this->adapter->getSharedTables() && $collection->getTenant() !== $this->adapter->getTenant()) {
329+
if ($this->adapter->getSharedTables() && $collection->getTenant() != $this->adapter->getTenant()) {
330330
throw new NotFoundException('Collection not found');
331331
}
332332

@@ -354,7 +354,7 @@ public function getSizeOfCollectionOnDisk(string $collection): int
354354
throw new NotFoundException('Collection not found');
355355
}
356356

357-
if ($this->adapter->getSharedTables() && $collection->getTenant() !== $this->adapter->getTenant()) {
357+
if ($this->adapter->getSharedTables() && $collection->getTenant() != $this->adapter->getTenant()) {
358358
throw new NotFoundException('Collection not found');
359359
}
360360

@@ -388,7 +388,7 @@ public function deleteCollection(string $id): bool
388388
throw new NotFoundException('Collection not found');
389389
}
390390

391-
if ($this->adapter->getSharedTables() && $collection->getTenant() !== $this->adapter->getTenant()) {
391+
if ($this->adapter->getSharedTables() && $collection->getTenant() != $this->adapter->getTenant()) {
392392
throw new NotFoundException('Collection not found');
393393
}
394394

src/Database/Traits/Documents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ public function upsertDocumentsWithIncrease(
14051405
if ($document->getTenant() === null) {
14061406
throw new DatabaseException('Missing tenant. Tenant must be set when tenant per document is enabled.');
14071407
}
1408-
if (! $old->isEmpty() && $old->getTenant() !== $document->getTenant()) {
1408+
if (! $old->isEmpty() && $old->getTenant() != $document->getTenant()) {
14091409
throw new DatabaseException('Tenant cannot be changed.');
14101410
}
14111411
} else {

0 commit comments

Comments
 (0)