Skip to content

Commit c80db70

Browse files
abnegateclaude
andcommitted
fix: handle missing exception transforms in Mongo and Postgres adapters
- Mongo: extend createCollection pre-check to all collections in shared-tables mode, not just _metadata - Postgres: add 42P01 (Undefined table) → NotFoundException in processException - Postgres: wrap deleteCollection in try-catch with processException to match MariaDB behavior Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent be7a66c commit c80db70

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/Database/Adapter/Mongo.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,10 @@ public function createCollection(string $name, array $attributes = [], array $in
414414
{
415415
$id = $this->getNamespace() . '_' . $this->filter($name);
416416

417-
// For metadata collections outside transactions, check if exists first
418-
if (!$this->inTransaction && $name === Database::METADATA && $this->exists($this->getNamespace(), $name)) {
417+
// In shared-tables mode or for metadata, the physical collection may
418+
// already exist for another tenant. Return early to avoid a
419+
// "Collection Exists" exception from the client.
420+
if (!$this->inTransaction && ($this->getSharedTables() || $name === Database::METADATA) && $this->exists($this->getNamespace(), $name)) {
419421
return true;
420422
}
421423

src/Database/Adapter/Postgres.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,11 @@ public function deleteCollection(string $id): bool
439439
$sql = "DROP TABLE {$this->getSQLTable($id)}, {$this->getSQLTable($id . '_perms')}";
440440
$sql = $this->trigger(Database::EVENT_COLLECTION_DELETE, $sql);
441441

442-
return $this->getPDO()->prepare($sql)->execute();
442+
try {
443+
return $this->getPDO()->prepare($sql)->execute();
444+
} catch (PDOException $e) {
445+
throw $this->processException($e);
446+
}
443447
}
444448

445449
/**
@@ -2229,6 +2233,11 @@ protected function processException(PDOException $e): \Exception
22292233
return new LimitException('Datetime field overflow', $e->getCode(), $e);
22302234
}
22312235

2236+
// Unknown table
2237+
if ($e->getCode() === '42P01' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 7) {
2238+
return new NotFoundException('Collection not found', $e->getCode(), $e);
2239+
}
2240+
22322241
// Unknown column
22332242
if ($e->getCode() === "42703" && isset($e->errorInfo[1]) && $e->errorInfo[1] === 7) {
22342243
return new NotFoundException('Attribute not found', $e->getCode(), $e);

tests/e2e/Adapter/Scopes/CollectionTests.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,14 +1393,13 @@ public function testSharedTablesMultiTenantCreateCollection(): void
13931393
$col1Again = $database->getCollection($colName);
13941394
$this->assertFalse($col1Again->isEmpty());
13951395

1396-
// Cleanup: delete per-tenant metadata docs
1397-
$database->setTenant($tenant1);
1398-
$database->deleteCollection($colName);
1399-
$database->setTenant($tenant2);
1400-
$database->deleteCollection($colName);
1401-
14021396
if ($createdDb) {
14031397
$database->delete();
1398+
} else {
1399+
$database->setTenant($tenant1);
1400+
$database->deleteCollection($colName);
1401+
$database->setTenant($tenant2);
1402+
$database->deleteCollection($colName);
14041403
}
14051404

14061405
$database

0 commit comments

Comments
 (0)