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

Can't pickle GeoAlchemy PostGIS objects #24

Open
danpat opened this issue Jul 31, 2012 · 3 comments
Open

Can't pickle GeoAlchemy PostGIS objects #24

danpat opened this issue Jul 31, 2012 · 3 comments

Comments

@danpat
Copy link
Contributor

danpat commented Jul 31, 2012

Title says it all.

If you attempt something like:

objects = session.query(MyGeoObject).all()
pickle.dumps(objects)

You'll get :

TypeError: can't pickle buffer objects

The problem is that PostGIS returns a Buffer object for geometry columns, which pickle can't handle.

A quick fix is to convert the Buffer into a string so the objects are serializable by Pickle. This does make a copy of the returned object, but I don't think that's avoidable.

This probably applies to other database that return non-pickleable types for geometry columns, and the fix is probably similar, but I don't have access to any other databases to debug on.

@danpat
Copy link
Contributor Author

danpat commented Jul 31, 2012

Simple patch to fix:

--- a/geoalchemy/postgis.py
+++ b/geoalchemy/postgis.py
@@ -121,6 +121,7 @@ class PGSpatialDialect(SpatialDialect):
         return PGSpatialDialect.__functions

     def process_result(self, value, type):
+        value = str(value)
         if type.wkt_internal:
             return PGPersistentSpatialElement(WKTSpatialElement(value, type.srid))
         return PGPersistentSpatialElement(WKBSpatialElement(value, type.srid))

elemoine pushed a commit that referenced this issue Jan 9, 2013
@elemoine
Copy link
Member

elemoine commented Jan 9, 2013

This fix breaks the tests. I had to revert d7850ca. See ebcdb37.

@karankurani
Copy link

I have the same problem while using pylibmc to cache objects which have geometry columns. The pylibmc library uses pickle internally to serialize/deserialize objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants