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

schema().dumps not working properly with field initializers #60

Closed
ropottnik opened this issue Jan 29, 2019 · 1 comment
Closed

schema().dumps not working properly with field initializers #60

ropottnik opened this issue Jan 29, 2019 · 1 comment

Comments

@ropottnik
Copy link

ropottnik commented Jan 29, 2019

Consider the following dataclass:

from typing import List

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json

@dataclass_json
@dataclass
class Bar:
    foos: List[str] = field(default_factory=list)

using Bar.schema().dumps(Bar()) gives me the following error:

Traceback (most recent call last):
  File "dataclass_test.py", line 20, in <module>
    Bar.schema().dumps(Bar())
  File "~/.venv/venv/lib/python3.6/site-packages/dataclasses_json/api.py", line 100, in schema
    infer_missing)
  File "~/.venv/venv/lib/python3.6/site-packages/dataclasses_json/mm.py", line 90, in _make_default_fields
    cls)
  File "~/.venv/venv/lib/python3.6/site-packages/dataclasses_json/mm.py", line 105, in _make_default_field
    type_arg = type_.___args__[0]
AttributeError: type object 'List' has no attribute '___args__'

Process finished with exit code 1

However, it works when the type of foos is a List of another dataclass_json, like this:

@dataclass_json
@dataclass
class Foo:
    one: str


@dataclass_json
@dataclass
class Bar:
    foos: List[Foo] = field(default_factory=list)


if __name__ == "__main__":
    print(Bar.schema().dumps(Bar()))

So something seems to be off with types and field initializers

I am using dataclasses-json==0.2.1

@ghost
Copy link

ghost commented Feb 4, 2019

I've also just hit upon the exact same issue.

Peilonrayz added a commit to Peilonrayz/dataclasses-json that referenced this issue Feb 19, 2019
This was referenced Feb 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant