Skip to content

Commit 5eb02eb

Browse files
daniel-wernormanrz
andauthored
Fix dataset pickling (#1218)
* Add regression test for dataset picklability * try just string? * try copyreg * changelog --------- Co-authored-by: Norman Rzepka <[email protected]>
1 parent acc5eba commit 5eb02eb

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

webknossos/Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1919
### Changed
2020

2121
### Fixed
22+
- Fixed pickling issue that has been introduced in 0.15.9. [#1218](https://github.com/scalableminds/webknossos-libs/pull/1218)
2223

2324

2425
## [0.15.9](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.15.9) - 2024-11-25
@@ -32,7 +33,7 @@ Removed the CZI installation extra from `pip install webknossos[all]` by default
3233
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v0.15.7...v0.15.8)
3334

3435
### Changed
35-
- Fixes SSL certificate verification for remote datasets by adding CA certificates using `certifi`. [#1211](https://github.com/scalableminds/webknossos-libs/pull/1211)
36+
- Fixed SSL certificate verification for remote datasets by adding CA certificates using `certifi`. [#1211](https://github.com/scalableminds/webknossos-libs/pull/1211)
3637

3738

3839
## [0.15.7](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.15.7) - 2024-10-25

webknossos/tests/dataset/test_dataset_download_upload_remote.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pickle
12
from pathlib import Path
23
from tempfile import TemporaryDirectory
34
from time import gmtime, strftime
@@ -73,6 +74,10 @@ def test_url_open_remote(
7374
data,
7475
sample_dataset.get_color_layers()[0].get_finest_mag().read(),
7576
)
77+
assert set(pickle.loads(pickle.dumps(ds)).layers.keys()) == {
78+
"color",
79+
"segmentation",
80+
}, "Dataset instances should be picklable."
7681

7782

7883
def test_remote_dataset(sample_dataset: wk.Dataset) -> None:

webknossos/webknossos/dataset/defaults.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copyreg
12
import os
23
import ssl
34

@@ -6,6 +7,15 @@
67
from ..geometry import Vec3Int
78
from .data_format import DataFormat
89

10+
11+
def _save_sslcontext(
12+
obj: ssl.SSLContext,
13+
) -> tuple[type[ssl.SSLContext], tuple[ssl._SSLMethod]]:
14+
return obj.__class__, (obj.protocol,)
15+
16+
17+
copyreg.pickle(ssl.SSLContext, _save_sslcontext)
18+
919
DEFAULT_WKW_FILE_LEN = 32
1020
DEFAULT_CHUNK_SHAPE = Vec3Int.full(32)
1121
DEFAULT_DATA_FORMAT = (

0 commit comments

Comments
 (0)