Skip to content
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

Merged
merged 2 commits into from Dec 6, 2016

Conversation

sir-sigurd
Copy link
Member

@timgraham
Copy link
Member

@rcoup, @jtiai -- you two were involved in a previous attempt (#6934), any feedback on this approach?

@jtiai
Copy link

jtiai commented Nov 15, 2016

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 supports_empty_geometries is not even used anywhere, so is it really needed?

@sir-sigurd
Copy link
Member Author

@jtiai

I'm just not sure if passing responsibility to figure out geometry to Adapter best option here.

What do you mean by 'figure out geometry'?

Also to me it looks like whole supports_empty_geometries is not even used anywhere

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.

@jtiai
Copy link

jtiai commented Nov 20, 2016

@sir-sigurd

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
Copy link
Contributor

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)

Copy link
Member Author

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':
Copy link
Contributor

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?

@sir-sigurd sir-sigurd force-pushed the gis-db-empty-2 branch 2 times, most recently from 146fb76 to bb87061 Compare November 21, 2016 18:51
Copy link
Member

@timgraham timgraham left a 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'):
Copy link
Member

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.

@timgraham timgraham merged commit 183f501 into django:master Dec 6, 2016
@sir-sigurd sir-sigurd deleted the gis-db-empty-2 branch December 6, 2016 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants