You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're constructing ORM instances by specifying a WKT value as a string and inserting them as rows into PostgreSQL. If the ORM model instance is cached, later queries returning that row use the original string for the geometry, rather than the WKBElement value returned from the queries.
In particular, if an instance with geometry specified like Val(..., point='POINT(0 1)') is add'd to a session, and code is still holding a reference to it when a later query runs, that query will return the original instance directly without updating any properties (even though the query explicitly returns the appropriate WKBElement). Notes about the reproducer below:
the debug logging shows that the sa.select(Val) query is reading and converting the WKB correctly even in the BUG case
the printed queried.point is a string in the BUG case but WKBElement in the GOOD ones
expiring the instance doesn't work well when using async SQLAlchemy, but expunging does
This may not be a Geoalchemy2 bug per-se, but it's error prone: later calls to geoalchemy2.point.to_shape(queried.point) will explode because the input is a string, not something it understands.
Are there any SQLAlchemy tricks Geoalchemy2 can do to alleviate some of the danger here? For instance, convert to geometries specified as raw strings to be stored as WKTElement, so that they can be at least be safely passed to to_shape.
The text was updated successfully, but these errors were encountered:
Hi @huonw
Thanks for this report.
Indeed there is no automatic cast or even check in this case. I would suggest to explicitly use a WKTElement if you want to use a WKT string.
Thanks for Geoalchemy2!
We're constructing ORM instances by specifying a WKT value as a string and inserting them as rows into PostgreSQL. If the ORM model instance is cached, later queries returning that row use the original string for the geometry, rather than the
WKBElement
value returned from the queries.In particular, if an instance with geometry specified like
Val(..., point='POINT(0 1)')
isadd
'd to a session, and code is still holding a reference to it when a later query runs, that query will return the original instance directly without updating any properties (even though the query explicitly returns the appropriateWKBElement
). Notes about the reproducer below:sa.select(Val)
query is reading and converting the WKB correctly even in theBUG
casequeried.point
is a string in theBUG
case butWKBElement
in theGOOD
onesThis may not be a Geoalchemy2 bug per-se, but it's error prone: later calls to
geoalchemy2.point.to_shape(queried.point)
will explode because the input is a string, not something it understands.Are there any SQLAlchemy tricks Geoalchemy2 can do to alleviate some of the danger here? For instance, convert to geometries specified as raw strings to be stored as
WKTElement
, so that they can be at least be safely passed toto_shape
.The text was updated successfully, but these errors were encountered: