Skip to main content

Questions tagged [pydantic-v2]

Pydantic V2 is a ground-up rewrite that offers many new features, performance improvements, and some breaking changes compared to Pydantic V1.

pydantic-v2
0 votes
1 answer
35 views

Pydantic type conversion on assignment

I want to use Pydantic to convert a plaintext string password to a hashed value of type bytes on assignment using a specific hash function. This is a minimal example, that shows my current (not-...
DevilsThumb's user avatar
1 vote
1 answer
20 views

Why can't my FastAPI Router parse Pydantic's Enum type when I use Union params?

My Question Here is the definition of my three Pydantic Model: class SplitType(str, enum.Enum): AUTO = "auto" CUSTOM = "custom" class DocumentConfigBase(BaseModel): '''...
Yu xin Dong's user avatar
2 votes
1 answer
63 views

Set Pydantic BaseModel field type dynamically when instantiating an instance?

With Pydantic is it possible to build a model where the type of one of its fields is set via an argument when creating an instance? For example: class Animal(BaseModel): name: str class Dog(...
Matt Sanders's user avatar
  • 9,833
0 votes
1 answer
49 views

Is it possible to get a dict of fields with FieldInfo from the Pydantic Dataclass?

When creating classes by inheriting from BaseModel, I can use the model_fields property to get a dict of field names, and FieldInfo, but how can I do it if I use the Pydantic Dataclass decorator ...
Michal's user avatar
  • 961
0 votes
1 answer
43 views

Inverted Inheritance Structure in Pydantic

I know the normal way of creating Models in Pydantic is by Subclassing and adding fields for example like this: from pydantic import BaseModel class Base(BaseModel): task_id: str task_type: ...
AliSot 2000's user avatar
0 votes
0 answers
39 views

Easier way to use ObjectID in MongoDB and pydantic

I have a custom pydantic model for MongoDb's ObjectID. class PyObjectId(ObjectId): @classmethod def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: Any) -> core_schema....
ProxilityProblemSolver's user avatar
1 vote
2 answers
68 views

Date, Decimal not JSON serializable when encoding a Pydantic model to send in a POST via requests

I am writing a script to post data from an internal system to a third party web API. Our internal system uses data Models defined in Pydantic. I am trying to send data in one of these models to the ...
MarkBenson's user avatar
0 votes
1 answer
30 views

Add Extra Field than Model in Pydantic which dependent in another field value

I am very new to fastAPI and I am trying to replicate Django models.SerializerMethodField() in pydantic base model, As in Django we can do class A(serailizer.Serializers): service = serializer....
Yubraj's user avatar
  • 35
0 votes
0 answers
23 views

Sphinx autodoc - Recursion error: maximum recursion depth exceeded

I am trying update our stravalib documentatio. We use Sphinx / pydata_sphinx_theme + the native sphinx.autodoc extension combined with autodoc-pydantic for JSON representations. Upon building the ...
Leah Wasser's user avatar
1 vote
0 answers
39 views

Pydantic V2 model field_validation is not executed with Form Data in Fastapi 0.111.0

For Form data, I defined class as mentioned here https://stackoverflow.com/a/60670614/6189499. Using pydantic v2, pydantic model is defined as @as_form class Test(BaseModel): param1: str c: ...
Himal Acharya's user avatar
2 votes
1 answer
54 views

Can't get validation to work for non-table SQLModel

I'm unable to get Pydantic validation working with and without SQLModel, and I'm unsure what I'm doing wrong. I'm unsure what I'm missing: the punchline is: validation doesn't seem to happen when I'd ...
thades's user avatar
  • 21
0 votes
2 answers
64 views

Pydantic v2 to JSON Schema translation: How to suppress autogeneration of "title" annotation in v2?

I am using Pydantic 2.6.4 to generate JSON schemas. If I write an attribute in a Pydantic model that has no value for "title" in its FieldInfo, Pydantic will always autogenerate one from the ...
metaMeddl's user avatar
3 votes
1 answer
122 views

Supply only payload schema for FastAPI endpoint without actual validation by Pydantic

I need to supply only payload schema for API endpoint without any Pydantic validation. I'm using: FastAPI==0.110.1 Pydantic v2 from typing import Literal, Annotated import uvicorn from fastapi ...
Альберт Александров's user avatar
0 votes
2 answers
77 views

Validation error when sending a json with the required field

I'm new to Pydantic and I'm not understanding why this is failing when the JSON has the key. from pydantic import BaseModel class Event(BaseModel): id: str external_data = """ { ...
hm-distro's user avatar
0 votes
0 answers
26 views

Pydantic @field_validator with mode before does not run

I'm using Pydantic v2 to validate. The raw input field rent_plan_id is a string, I want to convert it int before running any others validations. I configured as bellow but it seemed like the ...
Tien Manh's user avatar

15 30 50 per page
1
2 3 4 5
7