Cannot pickle Structs with cloudpickle
Open
Nobody has claimed this yet.
type: bug
- Dominant language
- Python
- Stars
- 441
- Forks
- 90
- Avg merge
- 1d 12m
- Merged PRs (30d)
- 5
Description
Describe the bug
csp.Structs don't work with cloudpickle.
To Reproduce
import csp
import cloudpickle
class C(csp.Struct):
a: int = 1
b: str = ""
c = C()
cloudpickle.loads(cloudpickle.dumps(c))
Expected behavior
Pickling and unpickling should work correctly.
Error Message
Traceback (most recent call last):
File "/data01/ac14141/github/ray/csp/t.py", line 9, in <module>
cloudpickle.loads(cloudpickle.dumps(c))
File "/data01/ac14141/.venvs/csp-ray/lib/python3.12/site-packages/cloudpickle/cloudpickle.py", line 553, in _make_skeleton_class
skeleton_class = types.new_class(
^^^^^^^^^^^^^^^^
File "/data01/ac14141/.venvs/csp-ray/lib/python3.12/types.py", line 74, in new_class
return meta(name, resolved_bases, ns, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data01/ac14141/github/ray/csp/csp/impl/struct.py", line 83, in __new__
res = super().__new__(cls, name, bases, dct)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Struct.cpp:StructMeta:49:TypeError: Struct types must define at least 1 field
Runtime Environment
import sys, csp; print(csp.__version__); print(sys.version); print(sys.platform)
0.14.0
3.12.12 | packaged by conda-forge | (main, Jan 26 2026, 23:51:32) [GCC 14.3.0]
linux
Additional context
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the supplied Python cloudpickle round-trip first, then inspect csp/impl/struct.py around the Struct metaclass new call at line 83. Done means the provided C instance can be serialized and deserialized with cloudpickle without the Struct types must define at least 1 field error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100