Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

TypeError thrown from valid Union type #190

Closed
Wombatpm opened this issue Sep 6, 2022 · 2 comments · Fixed by #191
Closed

TypeError thrown from valid Union type #190

Wombatpm opened this issue Sep 6, 2022 · 2 comments · Fixed by #191

Comments

@Wombatpm
Copy link

Wombatpm commented Sep 6, 2022

We've been using dataclasses-jsonschema for awhile. After updating from 2.15.1 to 2.15.2. the following errors started to occur:

  File "/Users/XXX/.virtualenvs/customer-implementations/lib/python3.7/site-packages/dataclasses_jsonschema/__init__.py", line 420, in to_dict
    value = self._encode_field(f.field.type, value, omit_none)
  File "/Users/XXX/.virtualenvs/customer-implementations/lib/python3.7/site-packages/dataclasses_jsonschema/__init__.py", line 360, in _encode_field
    return encoder(field_type, value, omit_none)
  File "/Users/XXX/.virtualenvs/customer-implementations/lib/python3.7/site-packages/dataclasses_jsonschema/__init__.py", line 304, in encoder
    def encoder(ft, val, o): return cls._encode_field(unwrap_optional(ft), val, o)
  File "/Users/XXX/.virtualenvs/customer-implementations/lib/python3.7/site-packages/dataclasses_jsonschema/__init__.py", line 323, in _encode_field
    for variant in field_args:
  File "/Users/XXX/.virtualenvs/customer-implementations/lib/python3.7/site-packages/dataclasses_jsonschema/__init__.py", line 322, in <lambda>
    field_args = filter(lambda x: not issubclass(x, primitives), field_type.__args__)
TypeError: issubclass() arg 1 must be a class

reverting back to 2.15.1 resolved the error.

Confirmed that the order of variables on line 322 is wrong.

@Wombatpm Wombatpm changed the title Possible bug in 2.15.2 Bug in 2.15.2 Sep 6, 2022
@goldpbear
Copy link

goldpbear commented Sep 6, 2022

We started seeing a similar crash last Friday, preceded by this error (for one of our particular dataclasses, though it seems like maybe the issue is with Unions?):

Traceback (most recent call last):
  File "/var/task/dataclasses_jsonschema/__init__.py", line 296, in _encode_field
    encoder = cls.__encode_cache[field_type]  # type: ignore
KeyError: typing.Union[str, typing.Dict[str, str]]

Hopefully that's useful extra info...

And reverting to 2.15.1 resolved it for us as well.

@s-knibbs s-knibbs changed the title Bug in 2.15.2 TypeError thrown from valid Union type Sep 7, 2022
@Wombatpm
Copy link
Author

Wombatpm commented Sep 8, 2022

Thanks. I tested your changes in our system and they resolve our issues. What is the timeline for next release?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants