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

Support for collections other than list, for example dict #6

Open
bramp opened this issue Jul 2, 2024 · 2 comments
Open

Support for collections other than list, for example dict #6

bramp opened this issue Jul 2, 2024 · 2 comments

Comments

@bramp
Copy link

bramp commented Jul 2, 2024

I would like to encode a dict[str, SomeBaseModel], but currently it fails with:

class MyCollection(BaseCollectionModel[MyModel]):
    pass
pydantic_core._pydantic_core.ValidationError: 1 validation error for MyCollection
  Input should be a valid list [type=list_type, input_value={...}, input_type=dict]
@romis2012
Copy link
Owner

This feature may be added in the next major version.
Right now you can use pydantic RootModel:

class MyCollection(RootModel[dict[str, SomeBaseModel]]):
    pass

@bramp
Copy link
Author

bramp commented Jul 4, 2024

Ah thanks!

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

2 participants