Skip to content

Commit

Permalink
Merge pull request #768 from danielballan/test-double-pickle
Browse files Browse the repository at this point in the history
Fix bug with pickling `Context`
  • Loading branch information
gwbischof authored Jul 15, 2024
2 parents 356dbab + 22c217b commit 9398939
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Write the date in place of the "Unreleased" in the case a new version is release

# Changelog

## Unreleased

### Fixed
- A bug in `Context.__getstate__` caused picking to fail if applied twice.

## v0.1.0b5 (2024-06-27)

### Added
Expand Down
10 changes: 8 additions & 2 deletions tiled/_tests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ def test_pickle_clients(structure_clients, tmpdir):
for segment in segements:
original = original[segment]
roundtripped = pickle.loads(pickle.dumps(original))
assert roundtripped.uri == original.uri
roundtripped_twice = pickle.loads(pickle.dumps(roundtripped))
assert roundtripped.uri == roundtripped_twice.uri == original.uri


def test_lock_round_trip(tmpdir):
cache = Cache(tmpdir / "http_response_cache.db")
cache_round_tripped = pickle.loads(pickle.dumps(cache))
cache_round_tripped_twice = pickle.loads(pickle.dumps(cache_round_tripped))
# implementation detail!
assert cache._lock.lock is cache_round_tripped._lock.lock
assert (
cache._lock.lock
is cache_round_tripped._lock.lock
is cache_round_tripped_twice._lock.lock
)
2 changes: 2 additions & 0 deletions tiled/client/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def __setstate__(self, state):
)
self.http_client = httpx.Client(
verify=verify,
transport=Transport(cache=cache),
cookies=cookies,
timeout=timeout,
headers=headers,
Expand All @@ -246,6 +247,7 @@ def __setstate__(self, state):
)
self._token_cache = token_cache
self._cache = cache
self._verify = verify
self.server_info = server_info

@classmethod
Expand Down

0 comments on commit 9398939

Please sign in to comment.