dataclasses-json
dataclasses-json copied to clipboard
Unknown type warning for int type
I am getting the following warning when schema is being generated, even though the serialization works correctly.
UserWarning: Unknown type int at User.id: id It's advised to pass the correct marshmallow type to
mm_field``
This is the dataclass being processed.
@dataclass_json
@dataclass(frozen=True)
class User:
id: int
If I set a custom config for the field, there's no more warning.
id: int = field(
metadata=config(
mm_field=fields.Integer()
))
While debugging I noticed origin
field as being a string with the value int
, so it's not in TYPES
dict.
https://github.com/lidatong/dataclasses-json/blob/3dc59e01ccdfec619ee4e4c3502b9759b67c3fa8/dataclasses_json/mm.py#L258
I got same issue. Did you resolve it?
Check out #340 also.
Had the same problem, and then realized it was because i was using from __future__ import annotations
in the same file (for another class). Splitting them and severing the dependency in the file containing my DataClassJsonMixin
(or dataclass_json
) solved the issue on my side
I was not able to recreate any issues from above information.
Can you confirm it is still an issue and provide information such as dataclasses-json version, python version, etc., as well as a full example triggering the warning?
Closed for being stale. Please reopen if the issue persists
I've come across the same issue. Here's a basic example that should create this issue.
from __future__ import annotations
from dataclasses import dataclass
from dataclasses_json import dataclass_json
@dataclass_json
@dataclass
class Player:
id: int
name: str
data = '{"id": 1, "name": "John"}'
players = Player.schema().loads(data)
As far as I can tell, this only happens if you use from __future__ import annotations
along with .schema()
in the same file.
(Version 0.6.4, Python 3.11.7)
Same here