pydantic Questions

2

Solved

Using pydantic setting management, how can I load env variables on nested setting objects on a main settings class? In the code below, the sub_field env variable field doesn't get loaded. field_one...
Buhl asked 11/3, 2023 at 21:47

2

Solved

from pydantic import BaseModel class A(BaseModel): date = '' class B(A): person: float def __init__(self): self.person = 0 B() tried to initiate class B but raised error AttributeError: '...
Parcenary asked 25/11, 2022 at 12:39

2

Solved

Consider this code: from pydantic import BaseModel class MyModel(BaseModel): x: int appc = Celery(...) @appc.task(bind=True) def mytask(self): return [MyModel(x=0)] res = mytask.delay().get()...
Doti asked 25/3, 2021 at 15:44

6

I would like to instantiate a typing Union of two classes derived from pydantic.BaseModel directly. However I get a TypeError: Cannot instantiate typing.Union. All examples I have seen declare Unio...
Zitella asked 7/1, 2020 at 17:27

4

How to convert string to model type in FastAPI? If I have Student model and want to convert string student to type model. How to convert it? engine = create_engine(SQLALCHAMY_DATABASE_URL,pool_pre_...
Agenesis asked 30/5, 2023 at 10:33

3

Solved

I have the following pydantic model which contains a result typed as Union[int,float] as listed below. from typing import Union from pydantic import BaseModel class Calculation(BaseModel): arg1...
Hebrews asked 17/12, 2021 at 22:45

4

Solved

I am doing a microservice with a document loader, and the app can't launch at the import level, when trying to import langchain's UnstructuredMarkdownLoader $ flask --app main run --debug Traceback...
Crutcher asked 23/5, 2023 at 10:6

4

Solved

Recently I have started to use hydra to manage the configs in my application. I use Structured Configs to create schema for .yaml config files. Structured Configs in Hyda uses dataclasses for type ...
Brookhouse asked 9/1, 2022 at 8:22

3

Solved

I'm trying to update my code to pydantic v2 and having trouble finding a good way to replicate the custom types I had in version 1. I'll use my custom date type as an example. The original implemen...
Shekinah asked 13/9, 2023 at 22:43

4

Solved

I would like to create automated examples of valid data based on my pydantic models. How can I do this? Example: import pydantic from typing import Any class ExampleData(pydantic.BaseModel): a: ...
Palikar asked 28/8, 2023 at 14:17

4

Solved

How can I define a recursive Pydantic model? Here's an example of what I mean: from typing import List from pydantic import BaseModel class Task(BaseModel): name: str subtasks: List[Task] = [] ...
Malo asked 22/6, 2021 at 22:43

3

Solved

According to the docs: allow_mutation whether or not models are faux-immutable, i.e. whether setattr is allowed (default: True) Well I have a class : class MyModel(BaseModel): field1:int clas...
Kayo asked 2/5, 2022 at 13:59

2

Solved

I need to create a schema but it has a column called global, and when I try to write this, I got an error. class User(BaseModel): id:int global:bool I try to use another name, but gives another...
Obelisk asked 4/1, 2022 at 20:34

2

Solved

I'm following this tutorial to adapt it to my needs, in this case, to perform a sql module where I need to record the data collected by a webhook from the gitlab issues. For the database module I'm...
Disenthral asked 22/3, 2022 at 10:38

7

In pydantic is there a cleaner way to exclude multiple fields from the model, something like: class User(UserBase): class Config: exclude = ['user_id', 'some_other_field'] I am aware that fol...
Reikoreilly asked 5/1, 2022 at 3:31

6

Solved

All of sudden langchain_community & langchain packages started throwing error: TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard' The error getting ge...
Kempe asked 7/6, 2024 at 19:21

7

Solved

I want to use Arrow type in FastAPI response because I am using it already in SQLAlchemy model (thanks to sqlalchemy_utils). I prepared a small self-contained example with a minimal FastAPI app. I ...
Nachison asked 25/8, 2021 at 21:57

9

Solved

Is there a straight-forward approach to generate a Pydantic model from a dictionary? Here is a sample of the data I have. { 'id': '424c015f-7170-4ac5-8f59-096b83fe5f5806082020', 'contacts': [{ '...
Ovenbird asked 8/6, 2020 at 17:9

5

Solved

I have a BaseModel like this from pydantic import BaseModel class TestModel(BaseModel): id: int names: str = None While I validate some data like this TestModel(id=123).dict() I got resul...
Sunroom asked 7/5, 2020 at 3:11

2

Solved

I am using FastAPI to write a web service. It is good and fast. FastAPI is using pydantic models to validate input and output data, everything is good but when I want to declare a nested model for...
Westerly asked 29/4, 2020 at 8:15

2

Pydantic 2.0 seems to have drastically changed. Previously with FastAPI and Pydantic 1.X I could define the schema like this, where receipt is optional: class VerifyReceiptIn(BaseModel): device_id...
Hekker asked 14/7, 2023 at 18:55

4

Solved

I want to allow users to selectively update fields using PUT calls. On the pydantic model, I have made the fields Optional. In the FastAPI handler if the model attribute is None, then the field was...
Milfordmilhaud asked 16/2, 2021 at 17:38

2

I'm currently writing a few end points for an API in fastAPI. I'm defining classes that extend fastapi's HTTPException. The problem is that HTTPException returns a response body with an attribute c...
Fluctuate asked 19/2, 2021 at 7:9

4

Solved

I have the following Pydantic model: from pydantic import BaseModel import key class Wallet(BaseModel): private_key: str = Field(default_factory=key.generate_private_key) address: str I want ad...
Mullens asked 1/12, 2021 at 12:57

1

Solved

Let's say I have a Pydantic model with validation: Name = Annotated[str, AfterValidator(validate_name)] class Foo(BaseModel): id: UUID = Field(default_factory=uuid4) name: Name And a FastAPI en...
Kbp asked 24/5, 2024 at 9:5

© 2022 - 2025 — McMap. All rights reserved.