dask / dask/distributed

TypeError when serializing tuples of dataclasses

Open
#5,495 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.7k
Forks
778
Avg merge
2h 50m
Merged PRs (30d)
3

Description

**What happened**:

Calling `client.compute()` on a tuple such as `([dataclass_instance],)` results in a `TypeError` as `__init__` is apparently called because it thinks that the result is a task of some kind?

**What you expected to happen**:

It to not error.

**Minimal Complete Verifiable Example**:

```python
import dask.distributed
import dataclasses

@dataclasses.dataclass()
class Foo:
x: int

def entrypoint():
client = dask.distributed.get_client()
value = [Foo(x=1)],
return client.compute(value, sync=True)

if __name__ == '__main__':
from distributed import Client
with Client() as client:
client.submit(entrypoint).result()
```

Results in:

```
distributed.worker - WARNING - Compute Failed
Function: execute_task
args: ([(, , (), (, []))])
kwargs: {}
Exception: 'TypeError("__init__() missing 1 required positional argument: \'x\'")'

distributed.worker - WARNING - Compute Failed
Function: entrypoint
args: ()
kwargs: {}
Exception: 'TypeError("__init__() missing 1 required positional argument: \'x\'")'

Traceback (most recent call last):
File "test.py", line 23, in
results, = client.submit(entrypoint).result()
File "/Users/foo/lib/python3.8/site-packages/distributed/client.py", line 233, in result
raise exc.with_traceback(tb)
File "test.py", line 17, in entrypoint
return client.compute(results, sync=True)
File "/Users/foo/lib/python3.8/site-packages/distributed/client.py", line 2898, in compute
result = self.gather(futures)
File "/Users/foo/lib/python3.8/site-packages/distributed/client.py", line 1969, in gather
return self.sync(
File "/Users/foo/lib/python3.8/site-packages/distributed/client.py", line 865, in sync
return sync(
File "/Users/foo/lib/python3.8/site-packages/distributed/utils.py", line 327, in sync
raise exc.with_traceback(tb)
File "/Users/foo/lib/python3.8/site-packages/distributed/utils.py", line 310, in f
result[0] = yield future
File "/Users/foo/lib/python3.8/site-packages/tornado/gen.py", line 762, in run
value = future.result()
File "/Users/foo/lib/python3.8/site-packages/distributed/client.py", line 1834, in _gather
raise exception.with_traceback(traceback)
File "/Users/foo/lib/python3.8/site-packages/dask/utils.py", line 37, in apply
return func(*args)
TypeError: __init__() missing 1 required positional argument: 'x'
```

**Anything else we need to know?**:

Returning a plain list works fine.

**Environment**:

- Dask version: 2021.10.0
- Python version: 3.8.12
- Operating System: MacOS, also happens in distributed gateway clusters running Linux
- Install method (conda, pip, source): Pip via Poetry

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.