Skip to content

How to store references to objects in pydantic models, not copies #2929

Discussion options

You must be logged in to vote

Hi @theRealSuperMario
Have you checked Config.copy_on_model_validation ? :)

class Point(BaseModel):
    x: float
    y: float
    z: float

    def __init__(self, x, y, z) -> None:
        super().__init__(x=x, y=y, z=z)

    class Config:
        copy_on_model_validation = False

Hope it helps!

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@theRealSuperMario
Comment options

@theRealSuperMario
Comment options

Answer selected by PrettyWood
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants