Skip to content

Deserialize a null list field as None instead of raising (#131)#228

Open
CedricConday wants to merge 1 commit into
XeroAPI:masterfrom
CedricConday:fix/131-deserialize-list-none
Open

Deserialize a null list field as None instead of raising (#131)#228
CedricConday wants to merge 1 commit into
XeroAPI:masterfrom
CedricConday:fix/131-deserialize-list-none

Conversation

@CedricConday

Copy link
Copy Markdown

Fixes #131

Some Xero API responses return null for a field typed as an array. For example payroll_au_api.reject_leave_application(...) responds with:

{"Id": "...", "Status": "OK", "LeaveApplications": null}

Deserializing this raises:

TypeError: 'NoneType' object is not iterable

because deserialize_list does [deserialize(...) for sub_data in data] without guarding against data is None.

Change

Return None early when data is None, faithfully representing the null field. This mirrors deserialize_model, which already special-cases a None payload.

def deserialize_list(data_type, data, model_finder):
    if data is None:
        return None
    ...

Test

Added test_deserialize_list_none. It fails on master (TypeError) and passes with the fix. Full test_api_client suite (148 tests) stays green.

The Xero API can return null for an array field (e.g.
reject_leave_application responds with "LeaveApplications": None).
deserialize_list then tried to iterate over None and raised
TypeError: 'NoneType' object is not iterable.

Return None when data is None, mirroring how deserialize_model already
handles a null payload.

Closes XeroAPI#131.
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

Successfully merging this pull request may close these issues.

reject_leave_application: TypeError: 'NoneType' object is not iterable

1 participant