dataclasses-json icon indicating copy to clipboard operation
dataclasses-json copied to clipboard

Unknown type warning for int type

Open vicusbass opened this issue 4 years ago • 2 comments

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

vicusbass avatar Nov 24 '20 10:11 vicusbass

I got same issue. Did you resolve it?

pingsutw avatar Oct 20 '21 06:10 pingsutw

Check out #340 also.

meawoppl avatar Apr 07 '22 17:04 meawoppl

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

sbeginCoveo avatar Nov 01 '22 14:11 sbeginCoveo

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?

matt035343 avatar Jun 10 '23 18:06 matt035343

Closed for being stale. Please reopen if the issue persists

matt035343 avatar Jul 16 '23 10:07 matt035343

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)

frostyfalls avatar Feb 22 '24 06:02 frostyfalls

Same here

zintus avatar Mar 18 '24 17:03 zintus