ST_MakeEnvelope breaks MariaDB and fails on MySQL with SRID 4326 spatial columns
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
Research direction
Review server/src/Http/Controllers/Internal/v1/LiveController.php and the whereRaw calls in drivers(), vehicles(), and places(). Run the affected live endpoint queries against MySQL and MariaDB with SRID-4326 spatial data; done means the bounds filter works without GIS errors on both database engines.
Written by the indexing model from the issue text.
Description
Summary
LiveController builds the map-viewport spatial filter for the /v1/internal/live/{drivers,vehicles,places} endpoints using MySQL's ST_MakeEnvelope. This breaks the application in two ways:
-
MariaDB does not implement
ST_MakeEnvelope. It is a MySQL-only convenience function (5.7.6+). Calling these endpoints on any MariaDB-backed deployment returns a 500. MariaDB is otherwise a first-class target — recent migrations gate driver-specific branches onin_array(DB::getDriverName(), ['mysql', 'mariadb'])(e.g.2025_08_28_045009_noramlize_uuid_foreign_key_columns.php,2025_08_28_054925_create_devices_table.php), and the bundled spatial library (fleetbase/laravel-mysql-spatial) advertises MariaDB support — so this is the one outlier blocking MariaDB. -
On MySQL,
ST_MakeEnvelopeonly accepts SRID 0 geometries. Fleetbase'sPoint,Polygon, andMultiPolygoncasts (server/src/Casts/) feed geometries throughUtils::createSpatialExpressionFromGeoJson→\Fleetbase\LaravelMysqlSpatial\Types\Geometry::fromJson(...), which emits SRID 4326. Recent migrations such as2025_10_27_171322_fix_device_column_names.phpexplicitly normalize positions toST_SRID(POINT(0, 0), 4326). Mixing a SRID-0 envelope with SRID-4326 column data on MySQL 8 raisesER_GIS_DIFFERENT_SRIDS(3618) orER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS(3680) the moment the bounds filter actually meets a populated row, so this is a latent correctness bug on plain MySQL too.
Affected code
server/src/Http/Controllers/Internal/v1/LiveController.php, three identical call sites:
drivers()— line 160vehicles()— line 202places()— line 245
Each is:
$query->whereRaw(
'ST_Within(location, ST_MakeEnvelope(POINT(?, ?), POINT(?, ?)))',
[$west, $south, $east, $north]
);
User-facing impact
- Calling
GET /v1/internal/live/drivers?bounds[]=…&bounds[]=…&bounds[]=…&bounds[]=…(or the vehicles / places equivalents) returns 500 on any MariaDB deployment, and on MySQL once the spatial column has any SRID-4326 data — which it always does, because the casts and recent migrations write SRID 4326. - This is the live map viewport filter used by the console map, so it is the primary spatial query a fresh install will hit.
Repro (documentation references)
- MariaDB miscellaneous GIS functions reference omits
ST_MakeEnvelope: https://mariadb.com/docs/server/reference/sql-statements/geometry-constructors/miscellaneous-gis-functions. - MySQL
ST_MakeEnvelopedocumentation states it is defined for SRID 0 only and raisesER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS/ER_GIS_DIFFERENT_SRIDSon non-zero-SRID inputs. - Fleetbase storage SRID is 4326: see
Fleetbase\LaravelMysqlSpatial\Types\Geometry::fromJson(used byUtils::createSpatialExpressionFromGeoJson) and the explicitST_SRID(POINT(0, 0), 4326)in2025_10_27_171322_fix_device_column_names.php.
Proposed fix
Replace ST_MakeEnvelope(POINT(?, ?), POINT(?, ?)) with an equivalent WKT polygon passed through ST_GeomFromText(?, 4326). This preserves the ST_Within(location, …) form (so a future SPATIAL INDEX on location remains usable), pins the envelope SRID to 4326 to match the column, and runs unchanged on MySQL 8 / 8.4 and MariaDB 10.5+ / 11.x.
PR following this issue.
Environment
- Repro confirmed by reading current
main(commit9394d4f); call sites unchanged from the lines cited above. - Reproduces on any MariaDB version; on MySQL 8.0 / 8.4 with the default cast pipeline writing SRID 4326.
- Dominant language
- PHP
- Stars
- 34
- Forks
- 65
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 31
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fleetbase/fleetops
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 42/100
-
enhancement good first issue help wanted
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
enhancement good first issue help wanted
Difficulty 5/5 Over a week Newbie friendliness 30/100
All issues in fleetbase/fleetops
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·