question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't pickle overpy.Result

See original GitHub issue
Issue type
  • Bug Report
OverPy version
0.4
OS
  • Windows 7 x64 HP

Python version

  • Python 3.5 x64
Summary

Neither pickle nor _pickle Python modules can’t dump query result.

Steps to reproduce
import overpy
import pickle

op = overpy.Overpass()
sample = op.query("""
    way(50.746,7.154,50.748,7.157) ["highway"];
    (._;>;);
    out body;
    """)

with open('sample.pcl', 'wb') as pcl:
    pickle.dump(sample, pcl)
Expected results

pcl-file full of usefull data =)

Actual results

Empty plc-file and exception:

     11 with open('sample.pcl', 'wb') as pcl:
---> 12     pickle.dump(sample, pcl)

AttributeError: Can't pickle local object 'Element.__init__.<locals>.<lambda>'

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
phiboscommented, Apr 7, 2017

Thanks for reporting the issue.

I have merged a fix into the master branch and it will be in the next release.

0reactions
peci1commented, Oct 25, 2022

Here’s our workaround for Python 2.7:

import overpy
import pickle

op = overpy.Overpass()
sample = op.query("""
    way(50.746,7.154,50.748,7.157) ["highway"];
    (._;>;);
    out body;
    """)

def make_overpy_picklable(data):
    if hasattr(data, '_attribute_modifiers'):
        data._attribute_modifiers = None
    return data


def make_overpy_result_picklable(sample):
    sample = make_overpy_picklable(sample)
    for i in range(len(sample.nodes)):
        sample.nodes[i] = make_overpy_picklable(sample.nodes[i])
    for i in range(len(sample.ways)):
        sample.ways[i] = make_overpy_picklable(sample.ways[i])
    for i in range(len(sample.areas)):
        sample.areas[i] = make_overpy_picklable(sample.areas[i])
    for i in range(len(sample.relations)):
        sample.relations[i] = make_overpy_picklable(sample.relations[i])
    return sample

sample = make_overpy_result_picklable(sample)

with open('sample.pcl', 'wb') as pcl:
    pickle.dump(sample, pcl)

Deleting the dictionary is not a problem as it is only needed in the constructor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python multiprocessing PicklingError: Can't pickle <type ...
It appears that the result of applying functool.partial to a top-level function is also pickle-able, even if it's defined inside another function. –...
Read more >
API Reference — Python Overpass API 0.6 documentation
DataIncomplete – The requested way is not available in the result cache. overpy.exception.DataIncomplete – If resolve_missing is True and the area can't be ......
Read more >
How to Make Pickles–3 Rules You Can't Break
Making homemade pickles couldn't be easier. A little prep work with pretty basic ingredients can yield very tasty results.
Read more >
cannot pickle '_thread.lock' object when trying to start process ...
The problem here is that self in function run_parallel() can't be pickled as it ... Queue instance to this function is for results,...
Read more >
Pickle Science: How to Master the Preserving Power of Acids
Just like lacto-fermented pickles in the crock, these cucumbers need to stay submerged in the pickling solution. A loose pack results in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found