Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,10 @@ protected function handleSpatialQueries(Query $query, array &$binds, string $att
$binds[":{$placeholder}_0"] = $this->convertArrayToWKT($query->getValues()[0]);
return "NOT ST_Contains({$alias}.{$attribute}, " . $this->getSpatialGeomFromText(":{$placeholder}_0", null) . ")";

case Query::TYPE_IS_NULL:
case Query::TYPE_IS_NOT_NULL:
return "{$alias}.{$attribute} {$this->getSQLOperator($query->getMethod())}";

default:
throw new DatabaseException('Unknown spatial query method: ' . $query->getMethod());
}
Expand Down
4 changes: 4 additions & 0 deletions src/Database/Adapter/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,10 @@ protected function handleSpatialQueries(Query $query, array &$binds, string $att
? "NOT ST_Covers({$alias}.{$attribute}, " . $this->getSpatialGeomFromText(":{$placeholder}_0") . ")"
: "ST_Covers({$alias}.{$attribute}, " . $this->getSpatialGeomFromText(":{$placeholder}_0") . ")";

case Query::TYPE_IS_NULL:
case Query::TYPE_IS_NOT_NULL:
return "{$alias}.{$attribute} {$this->getSQLOperator($query->getMethod())}";

default:
throw new DatabaseException('Unknown spatial query method: ' . $query->getMethod());
}
Expand Down
47 changes: 47 additions & 0 deletions tests/e2e/Adapter/Scopes/SpatialTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,53 @@ public function testSpatialQueryCombinations(): void
}
}

public function testSpatialIsNullIsNotNull(): void
{
/** @var Database $database */
$database = $this->getDatabase();
if (!$database->getAdapter()->getSupportForSpatialAttributes()) {
$this->expectNotToPerformAssertions();
return;
}

$collectionName = 'spatial_null_checks';
try {
$database->createCollection($collectionName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Cleanup Masks Setup Failure

When createCollection() fails before collection metadata exists, the finally block still calls deleteCollection(). That cleanup throws NotFoundException for the missing metadata and replaces the original setup error, so the test reports the cleanup failure instead of the real failure.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/e2e/Adapter/Scopes/SpatialTests.php
Line: 1491

Comment:
**Cleanup Masks Setup Failure**

When `createCollection()` fails before collection metadata exists, the `finally` block still calls `deleteCollection()`. That cleanup throws `NotFoundException` for the missing metadata and replaces the original setup error, so the test reports the cleanup failure instead of the real failure.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex


$this->assertEquals(true, $database->createAttribute($collectionName, 'name', Database::VAR_STRING, 255, true));
// Optional spatial attribute: some documents legitimately have no location set.
$this->assertEquals(true, $database->createAttribute($collectionName, 'location', Database::VAR_POINT, 0, false));

$database->createDocument($collectionName, new Document([
'$id' => 'withLocation',
'name' => 'Has a location',
'location' => [40.7829, -73.9654],
'$permissions' => [Permission::read(Role::any())],
]));

$database->createDocument($collectionName, new Document([
'$id' => 'withoutLocation',
'name' => 'No location set',
'location' => null,
'$permissions' => [Permission::read(Role::any())],
]));

$withLocation = $database->find($collectionName, [
Query::isNotNull('location'),
], Database::PERMISSION_READ);
$this->assertCount(1, $withLocation);
$this->assertEquals('withLocation', $withLocation[0]->getId());

$withoutLocation = $database->find($collectionName, [
Query::isNull('location'),
], Database::PERMISSION_READ);
$this->assertCount(1, $withoutLocation);
$this->assertEquals('withoutLocation', $withoutLocation[0]->getId());
} finally {
$database->deleteCollection($collectionName);
}
}

public function testSpatialBulkOperation(): void
{
/** @var Database $database */
Expand Down
Loading