s-knibbs / dataclasses-jsonschema

JSON schema generation from dataclasses
MIT License
166 stars 38 forks source link

TypeError thrown from valid Union type #190

Closed Wombatpm closed 1 year ago

Wombatpm commented 1 year ago

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.

goldpbear commented 1 year ago

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.

Wombatpm commented 1 year ago

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