Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] TypeError: cannot pickle '..' - despite being excluded #531

Open
powellnorma opened this issue May 18, 2024 · 0 comments
Open

[BUG] TypeError: cannot pickle '..' - despite being excluded #531

powellnorma opened this issue May 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@powellnorma
Copy link

Description

Traceback (most recent call last):
  File "/tmp/test.py", line 38, in main
    print(t.to_json())
          ^^^^^^^^^^^
  File "/lib64/python3.11/site-packages/dataclasses_json/api.py", line 37, in to_json
    return json.dumps(self.to_dict(encode_json=False),
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib64/python3.11/site-packages/dataclasses_json/api.py", line 73, in to_dict
    return _asdict(self, encode_json=encode_json)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib64/python3.11/site-packages/dataclasses_json/core.py", line 417, in _asdict
    value = _asdict(
            ^^^^^^^^
  File "/lib64/python3.11/site-packages/dataclasses_json/core.py", line 439, in _asdict
    return copy.deepcopy(obj)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/copy.py", line 161, in deepcopy
    rv = reductor(4)
         ^^^^^^^^^^^
TypeError: cannot pickle '_asyncio.Task' object

Code snippet that reproduces the issue

@dataclass
class MyTask(DataClassJsonMixin):
    name: str
    task: asyncio.Task|None = field(default=None, metadata=config(exclude=lambda x:True))

async def main():
    t = MyTask("test", asyncio.create_task(asyncio.sleep(1)))
    print(t.to_json())

asyncio.run(main())

Describe the results you expected

I'd expect that it prints {name: "test"}

Python version you are using

Python 3.11.6

Environment description

dataclasses-json==0.6.6

@powellnorma powellnorma added the bug Something isn't working label May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant