Skip to content

Fix response parsing for MultipleItems requests #97

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Saltiola7
Copy link

Issue Description

When using the MultipleItems class to create multiple items at once, the SDK incorrectly tried to parse the API response as a CollectionItem object. However, when creating multiple items, the API returns a response with an items field containing a list of items, which should be parsed as a CollectionItemList object.

This caused a validation error:

pydantic_core._pydantic_core.ValidationError: 1 validation error for CollectionItem
field_data
  Field required [type=missing, input_value={'items': [{'id': '...', ...}]}, input_type=dict]

Solution

I modified the create_item method in client.py to check if the request is a MultipleItems object and, if so, parse the response as a CollectionItemList instead of a CollectionItem. This correctly handles the different response formats based on the request type.

Changes:

  1. Updated the return type annotation to typing.Union[CollectionItem, CollectionItemList]
  2. Added a conditional check to use the appropriate model for parsing based on the request type

Testing

I've tested this change by creating multiple items at once using the MultipleItems class, and the SDK now correctly parses the response without validation errors.

@Saltiola7 Saltiola7 mentioned this pull request Jun 3, 2025
@zplata
Copy link
Collaborator

zplata commented Jun 6, 2025

Hi @Saltiola7 - we'll take a look at this. Which version of the lib are you using?

@Saltiola7
Copy link
Author

2.0.0b1 in the pyproject.toml

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.

2 participants