New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #26789 -- Fixed handling of empty geometries in BaseSpatialField.get_db_prep_save #7428
Conversation
Feature wise implementation looks alright. I'm just not sure if passing responsibility to figure out geometry to Adapter best option here. Also to me it looks like whole |
What do you mean by 'figure out geometry'?
In this PR it's used to skip related test. Also it could be used to raise an exception if empty geometry is used on backend that doesn't support empty geometries (replacing empty geometry with NULL in query will lead to unexpected in some cases). But if we decide to do it, it should be done within another ticket. |
Sorry bad wording. I meant that if Adapter is correct place to make decision about empty geometry handling. Also doesn't Geometry class has .empty property you could test instead of WKT string? But beyond that, otherwise I think these changes are good to go. |
self._adapter.prepare(conn) | ||
|
||
def getquoted(self): | ||
""" | ||
Return a properly quoted string for use in PostgreSQL/PostGIS. | ||
""" | ||
if not self.ewkb: | ||
return "ST_GeomFromText('POINT EMPTY', %s)" % self.srid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's other types of empty geometry, shouldn't this be type-specific? (ala GEOMETRYCOLLECTION EMPTY
, POLYGON EMPTY
, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only POINT EMPTY
is not representable as WKB.
@@ -19,7 +19,9 @@ def __init__(self, obj, geography=False): | |||
|
|||
# Getting the WKB (in string form, to allow easy pickling of | |||
# the adaptor) and the SRID from the geometry or raster. | |||
if self.is_geometry: | |||
if isinstance(obj, PostGISAdapter) and not obj.ewkb or isinstance(obj, Geometry) and obj.wkt == 'POINT EMPTY': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check obj.empty
instead of serialising to WKT and checking the string?
146fb76
to
bb87061
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about whether to merge this as one commit or two. It looks a bit weird to have a commit which is presumably fixing stuff without any tests. Let me know what you think.
@@ -19,7 +19,12 @@ def __init__(self, obj, geography=False): | |||
|
|||
# Getting the WKB (in string form, to allow easy pickling of | |||
# the adaptor) and the SRID from the geometry or raster. | |||
if self.is_geometry: | |||
if (isinstance(obj, PostGISAdapter) and not obj.ewkb or | |||
isinstance(obj, Geometry) and obj.empty and obj.geom_type == 'Point'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a brief spot check, I noticed that no tests are failing if obj.geom_type == 'Point'
is removed. Not sure if it's something that should be tested or not.
454004b
to
b261db5
Compare
b261db5
to
2e844a5
Compare
2e844a5
to
183f501
Compare
https://code.djangoproject.com/ticket/26789