Skip to content

Incorrect behaviour in to_dict() #493

Description

@sgran

Expectation:
Calling to_dict() on a model class will produce a dictionary composed of base types that can be correctly serialized to/from json.

Behaviour:
Deeply nested lists appear to be incorrectly handled.

The following code:

importjsonfromplaid.model.country_codeimportCountryCodefromplaid.model.depository_account_subtypeimportDepositoryAccountSubtypefromplaid.model.depository_account_subtypesimportDepositoryAccountSubtypesfromplaid.model.depository_filterimportDepositoryFilterfromplaid.model.link_token_account_filtersimportLinkTokenAccountFiltersfromplaid.model.link_token_create_requestimportLinkTokenCreateRequestfromplaid.model.link_token_create_request_authimportLinkTokenCreateRequestAuthfromplaid.model.link_token_create_request_userimportLinkTokenCreateRequestUserfromplaid.model.productsimportProductsrequest=LinkTokenCreateRequest(
client_name="myClient",
country_codes=[CountryCode("US")],
language="en",
products=[Products("auth"), Products("transactions")],
user=LinkTokenCreateRequestUser(client_user_id="1234"),
account_filters=LinkTokenAccountFilters(
depository=DepositoryFilter(
account_subtypes=DepositoryAccountSubtypes([DepositoryAccountSubtype(value="CHECKING")])
)
),
auth=LinkTokenCreateRequestAuth(
instant_match_enabled=True,
),
)
print(json.dumps(request.to_dict()))

produces the following exception:

Traceback (most recent call last):
File "/Users/sgran/source/wagestream/us-ws-api/scratch/t.py", line 32, in <module>
print(json.dumps(request.to_dict()))
File "/opt/homebrew/Cellar/python@3.9/3.9.18_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/opt/homebrew/Cellar/python@3.9/3.9.18_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/opt/homebrew/Cellar/python@3.9/3.9.18_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/opt/homebrew/Cellar/python@3.9/3.9.18_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type DepositoryAccountSubtype is not JSON serializable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions