Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behaviour in to_dict() #493

Open
sgran opened this issue Nov 10, 2023 · 1 comment
Open

Incorrect behaviour in to_dict() #493

sgran opened this issue Nov 10, 2023 · 1 comment

Comments

@sgran
Copy link

sgran commented Nov 10, 2023

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:

import json

from plaid.model.country_code import CountryCode
from plaid.model.depository_account_subtype import DepositoryAccountSubtype
from plaid.model.depository_account_subtypes import DepositoryAccountSubtypes
from plaid.model.depository_filter import DepositoryFilter
from plaid.model.link_token_account_filters import LinkTokenAccountFilters
from plaid.model.link_token_create_request import LinkTokenCreateRequest
from plaid.model.link_token_create_request_auth import LinkTokenCreateRequestAuth
from plaid.model.link_token_create_request_user import LinkTokenCreateRequestUser
from plaid.model.products import Products

request = 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
@sgran
Copy link
Author

sgran commented Nov 10, 2023

It appears the problem is actually related to the use of DepositoryAccountSubtypes. If I substitute a simple [DepositoryAccountSubtype] for it in the schema, changing the constructor to:

request = 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=[DepositoryAccountSubtype(value="CHECKING")]
        )
    ),
    auth=LinkTokenCreateRequestAuth(
        instant_match_enabled=True,
    ),
)

the JSON serialization succeeds.

@plaid plaid deleted a comment from JefferyOsborne Dec 18, 2023
@plaid plaid deleted a comment from JefferyOsborne Feb 27, 2024
@plaid plaid deleted a comment from JefferyOsborne Feb 27, 2024
@plaid plaid deleted a comment from JefferyOsborne Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant