1

when trying to facilitate expand function to a FastAPI endpoint using relationships get a "cyclic reference" error.

when the user defines expand=parents, we expand only the first layer, where all parents and children will have to count on how many relations they have on each. which works well

What I want to achieve is when parents.parents is defined, or any combination of these to expand the nested layers. expand can be any combination of XXX.YYY.XXX...

I have written a helper_function only to include data up until the level requested by user using SQL alchemy relationships

using pydantic 2.0.3 pydantic_core 2.3.0 fastapi 0.110.0

example pydantic Schema

from typing import Optional, List, Union
Person(BaseModel):
    id: int
    name: str
    parents: Optional[Union[List['Person'], int]] = None
    children: Optional[Union[List['Person'], int]] = None
2
  • 1
    if Person's attribute parents is of type list, how can that attribute also have its own parents attribute? Can you please provide a reproducible example of code you want to execute, with a clear description of the output you wish to obtain, and what output you are obtaining instead? Commented Jun 22, 2024 at 22:02
  • idea is Person C, can have Person A and B as its parents and Persons D and E as Children. who are all Person ( or humans ) the relationship is linked via a relationship table where there could be entries of parant_id and child_id. Person table parents and children are back_populate fields which help with the SQL alchemy expand. Commented Jun 23, 2024 at 7:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.