-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Checks
- I added a descriptive title to this issue
- I have searched (google, github) for similar issues and couldn't find anything
- I have read and followed the docs and couldn't find an answer
- After submitting this, I commit to one of:
- Look through open issues and helped at least one other person
- Hit the "watch" button on this repo to receive notifications and I commit to help at least 2 people that ask questions in the future
- Implement a Pull Request for a confirmed bug
Question
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.6.1
pydantic compiled: False
install path: /home/christoph/.cache/pypoetry/virtualenvs/backend-WV529wjX-py3.8/lib/python3.8/site-packages/pydantic
python version: 3.8.3 (default, May 13 2020, 19:59:26) [GCC 9.2.0]
platform: Linux-5.4.67-x86_64-with-glibc2.2.5
optional deps. installed: ['typing-extensions']
...
Unfortunately not self-contained because database setup required, but I hope my goal is obvious.
This should work as per Recursive ORM Models, but I am getting the following error:
pydantic.error_wrappers.ValidationError: 1 validation error for Organization
E contents
E value is not a valid list (type=type_error.list)
When querying ORMOrganization, ORMOrganization.contents is of type ORMOrganizationContentSet([ORMOrganizationContent[UUID('249941bf-fe64-430e-ae38-7731e60a9940')]]). Pony's content set doesn't seem to work for the recursive ORM mode? iter(contents) works, so I am not sure where to go from here.
Changing the type of Organization.contents to Set[OrganizationContent] does not change anything.
I searched the issues here for PonyORM and did not find anything. I would much appreciate any help regarding this!
import pydantic
# Database classes:
class ORMOrganization(database.Entity):
id = PrimaryKey(UUID, default=uuid4, auto=True)
contents = Set('ORMOrganizationContent', reverse="organization")
class ORMOrganizationContent(database.Entity):
id = PrimaryKey(UUID, default=uuid4, auto=True)
organization = Required("ORMOrganization")
name = Required(str)
# Pydantic classes:
class OrganizationContent(pydantic.BaseModel):
id: UUID
name: str
class Config:
orm_mode = True
class Organization(pydantic.BaseModel):
id: UUID
contents: List[OrganizationContent]
class Config:
orm_mode = True