Skip to content

Add Property.to_json and from_json methods - #424

Merged
hobu merged 3 commits into
mainfrom
property-from_json-to_json
Sep 24, 2026
Merged

hobu merged 3 commits into
mainfrom
property-from_json-to_json

Conversation

@hobu

@hobu hobu commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Continuing #423, I've added index.Property.to_json and index.Property.from_json methods and beefed up the tests to account for those while dropping mention of pickle testing.

@hobu
hobu requested a review from adamjstewart September 23, 2026 17:59
@adamjstewart

Copy link
Copy Markdown
Collaborator

Needs the size check to avoid OOM errors and DoS attacks.

Comment thread tests/test_index.py


class TestPickling(unittest.TestCase):
# https://github.com/Toblerity/rtree/issues/87

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we actually want to keep these tests. I added these a while back to document that an Rtree can't be pickled, and therefore can't be used in a multiprocessing context on many platforms. This isn't related to pickling objects, it's pickling the entire index. This is still a desirable property to fix in the future.

@hobu hobu Sep 23, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand why there's a test that's marked as an expected failure. I thought it was a test that had rotted or something.

Shouldn't we instead nuke the __getstate__ and __setstate__ machinery if we want to short circuit index pickling?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the full history, the following bug reports:

document several complaints that pickling of an index (especially important in a multiprocessing context) is broken. I tried to hack getstate/setstate in #197 but you wanted a better long-term fix. So we merged only the xfail tests in #233 so it would be easier to test this in the future. #307 tries to document that this is broken.

I'm definitely happy with any real fix for pickling you're able to come up with.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I happily forgot all this stuff!

I think the challenge for pickling the index itself is in the context of multi-threaded operations, there's no mechanism in libspatialindex to serialize access to the thing.

@hobu
hobu merged commit f7c9ebd into main Sep 24, 2026
48 checks passed
@hobu
hobu deleted the property-from_json-to_json branch September 24, 2026 19:42
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

Successfully merging this pull request may close these issues.

2 participants