Skip to content

Containers of extended types do not work [bug] #191

@AndreyMZ

Description

@AndreyMZ

Steps to reproduce

Run the following tests by pytest:

from dataclasses import dataclass
from datetime import datetime, timezone
from decimal import Decimal
from typing import List
from uuid import UUID, uuid4

from dataclasses_json import DataClassJsonMixin


@dataclass
class Foo(DataClassJsonMixin):
    f1: datetime
    f2: Decimal
    f3: UUID

@dataclass
class Bar(DataClassJsonMixin):
    f1: List[datetime]
    f2: List[Decimal]
    f3: List[UUID]


def test_foo():
    foo_obj = Foo(
        f1=datetime.now(tz=timezone.utc),
        f2=Decimal(314),
        f3=uuid4(),
    )
    assert Foo.from_json(foo_obj.to_json()) == foo_obj

def test_bar():
    bar_obj = Bar(
        f1=[datetime.now(tz=timezone.utc)],
        f2=[Decimal(314)],
        f3=[uuid4()],
    )
    assert Bar.from_json(bar_obj.to_json()) == bar_obj

Actual result

test_foo passed.
test_bar failed:

Expected :Bar(f1=[datetime.datetime(2020, 3, 13, 6, 12, 1, 961388, tzinfo=datetime.timezone.utc)], f2=[Decimal('314')], f3=[UUID('8a82b5b9-d284-48c6-b4cf-a2bba2bbc8fb')])
Actual   :Bar(f1=[1584079921.961388], f2=['314'], f3=['8a82b5b9-d284-48c6-b4cf-a2bba2bbc8fb'])

Expected result

Both tests passed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions