Skip to content

base_geoengine: get_geo_equal_sql omits the SRID — geo_equal can never match #471

Description

@lesdekock

The defect

base_geoengine/geo_operators.py, get_geo_equal_sql builds its comparison value without a SRID:

compare_to = "ST_GeomFromText(%s)"

ST_GeomFromText without a SRID argument produces a geometry with SRID 0, while the column carries the field's SRID (3857 default, or whatever the field declares). PostGIS geometry equality between different SRIDs is never true, so a geo_equal domain always returns an empty set — silently, with no error.

Every other operator in the same file already passes the SRID — _get_postgis_comp_sql does:

return f"{op}({table}.{col}, ST_GeomFromText(%s, %s))"   # value + srid

get_geo_equal_sql alone omits it.

Affected

Verified present on 16.0, 17.0, 18.0 (geo_operators.py line ~49-51 on each), and carried into the 19.0 migration in #465.

The fix (proven downstream)

Mirror _get_postgis_comp_sql's SRID handling:

def get_geo_equal_sql(self, table, col, value, params):
    base = self.geo_field.entry_to_shape(value, same_type=False)
    srid = self.geo_field.srid
    params.append(base.wkt)
    params.append(srid)
    return f" {table}.{col} = ST_GeomFromText(%s, %s)"

We carry a vendored derivative of this module and shipped exactly this fix with a regression test (create a point, search [('geom', 'geo_equal', <same GeoJSON>)], expect the record back — fails empty before the fix, passes after). Happy to open a PR against any branch the maintainers prefer.

Found while porting the module's domain layer to Odoo 19, where a new test suite exercised each operator individually — the operator has no call sites in our production code, which is presumably why it went unnoticed; the first user to write a geo_equal domain gets silently empty results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions