Skip to content

fix: support isNull/isNotNull queries on spatial attributes#922

Merged
HarshMN2345 merged 1 commit into
mainfrom
fix-spatial-isnull-query
Jul 17, 2026
Merged

fix: support isNull/isNotNull queries on spatial attributes#922
HarshMN2345 merged 1 commit into
mainfrom
fix-spatial-isnull-query

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

  • MariaDB::handleSpatialQueries() and Postgres::handleSpatialQueries() threw Unknown spatial query method for any non-spatial query method (e.g. isNull/isNotNull) run against a spatial (point/linestring/polygon) attribute, since the switch only recognized true spatial predicates (ST_Contains, ST_Intersects, etc.) and threw on default.
  • This surfaces in production whenever a spatial attribute is made optional and later queried for null/not-null — a valid, expected use case (e.g. "show me records with/without a location set").
  • Root cause found while investigating a customer report of inconsistent listDocuments results on a collection with a spatial attribute that had recently been changed from required to optional.

Fix

Added Query::TYPE_IS_NULL / Query::TYPE_IS_NOT_NULL cases to both adapters' handleSpatialQueries(), generating plain IS NULL / IS NOT NULL SQL via the existing getSQLOperator() helper — safe regardless of column type.

Test plan

  • Added testSpatialIsNullIsNotNull to tests/e2e/Adapter/Scopes/SpatialTests.php — creates a collection with an optional spatial attribute, one document with a value set and one without, asserts isNotNull/isNull correctly partition them.
  • Ran the full e2e suite locally via docker compose exec tests vendor/bin/phpunit --filter=testSpatialIsNullIsNotNull — 16/16 pass across MariaDB, MySQL, Postgres, Mongo, SQLite, and shared-tables adapter variants.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed spatial queries using “is null” and “is not null” filters.
    • Spatial attributes can now be correctly matched based on whether they contain a value or are explicitly null.
  • Tests

    • Added coverage verifying nullability filtering for spatial attributes across supported database adapters.

MariaDB and Postgres adapters threw "Unknown spatial query method"
for any non-spatial query method (e.g. isNull/isNotNull) against a
spatial (point/linestring/polygon) attribute, since handleSpatialQueries()
only recognized true spatial predicates and threw on anything else.

This surfaces whenever a spatial attribute is made optional and later
queried for null/not-null, which is a valid and expected use case.
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 05df532a-492a-4cf8-b20e-758d04cb7244

📥 Commits

Reviewing files that changed from the base of the PR and between d5ebecc and f6c4ff0.

📒 Files selected for processing (3)
  • src/Database/Adapter/MariaDB.php
  • src/Database/Adapter/Postgres.php
  • tests/e2e/Adapter/Scopes/SpatialTests.php

📝 Walkthrough

Walkthrough

Changes

Spatial nullability

Layer / File(s) Summary
Spatial null query handling and coverage
src/Database/Adapter/MariaDB.php, src/Database/Adapter/Postgres.php, tests/e2e/Adapter/Scopes/SpatialTests.php
MariaDB and Postgres generate SQL for spatial isNull and isNotNull queries, with end-to-end tests covering nullable spatial attributes and expected document results.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: abnegate

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding isNull/isNotNull support for spatial attributes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-spatial-isnull-query

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds null checks for spatial attributes in SQL adapters. The main changes are:

  • MariaDB spatial queries now handle isNull and isNotNull.
  • Postgres spatial queries now handle isNull and isNotNull.
  • Spatial e2e coverage now checks optional point attributes with and without values.

Confidence Score: 5/5

The changed query handling looks safe to merge after a small test cleanup improvement.

  • The adapter SQL matches the existing non-spatial null-query behavior.
  • The remaining issue is limited to test diagnostics when collection setup fails.

tests/e2e/Adapter/Scopes/SpatialTests.php

Important Files Changed

Filename Overview
src/Database/Adapter/MariaDB.php Adds spatial null-query handling using the existing SQL null operator path.
src/Database/Adapter/Postgres.php Adds matching Postgres spatial null-query handling for geometry columns.
tests/e2e/Adapter/Scopes/SpatialTests.php Adds e2e coverage for optional spatial values, with one cleanup path that can mask setup failures.

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
tests/e2e/Adapter/Scopes/SpatialTests.php:1491
**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.

Reviews (1): Last reviewed commit: "fix: support isNull/isNotNull queries on..." | Re-trigger Greptile


$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

@HarshMN2345
HarshMN2345 merged commit a1796fd into main Jul 17, 2026
22 checks passed
@HarshMN2345
HarshMN2345 deleted the fix-spatial-isnull-query branch July 17, 2026 08:21
HarshMN2345 added a commit to appwrite/appwrite that referenced this pull request Jul 17, 2026
Pulls in the isNull/isNotNull-on-spatial-attribute fix
(utopia-php/database#922), confirmed above to turn the
new testSpatialQuery assertions from a 500 to a 200 in CI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants