fix: support isNull/isNotNull queries on spatial attributes#922
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughChangesSpatial nullability
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Greptile SummaryThis PR adds null checks for spatial attributes in SQL adapters. The main changes are:
Confidence Score: 5/5The changed query handling looks safe to merge after a small test cleanup improvement.
tests/e2e/Adapter/Scopes/SpatialTests.php Important Files Changed
Prompt To Fix All With AIFix 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); |
There was a problem hiding this comment.
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.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.
Summary
MariaDB::handleSpatialQueries()andPostgres::handleSpatialQueries()threwUnknown spatial query methodfor 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 ondefault.listDocumentsresults 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_NULLcases to both adapters'handleSpatialQueries(), generating plainIS NULL/IS NOT NULLSQL via the existinggetSQLOperator()helper — safe regardless of column type.Test plan
testSpatialIsNullIsNotNulltotests/e2e/Adapter/Scopes/SpatialTests.php— creates a collection with an optional spatial attribute, one document with a value set and one without, assertsisNotNull/isNullcorrectly partition them.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
Tests