konradhalas / dacite

Simple creation of data classes from dictionaries.
MIT License
1.72k stars 106 forks source link

Incorrect work when using field with default_factory #215

Closed kwist-sgr closed 1 year ago

kwist-sgr commented 1 year ago

Describe the bug default_factory is called only once if a field absent in the data

To Reproduce

#!/usr/bin/env python

from dataclasses import field, dataclass

from dacite import from_dict

@dataclass
class A:
    name: str
    items: list[str] = field(default_factory=list)

if __name__ == '__main__':
    a1 = from_dict(A, {'name': 'a1'})
    a2 = from_dict(A, {'name': 'a2'})
    print('Test identity:', a1.items is a2.items)

Output

Test identity: True

Expected behavior items shouldn't be identical. dacite v1.7.0 works as expected

Test identity: False

Environment

mciszczon commented 1 year ago

Looks like a good v1.8.1 candidate. Thanks for reporting!.

ehiggs commented 1 year ago

@mciszczon is there a plan for 1.8.1?

mciszczon commented 1 year ago

@ehiggs Released today :)