Skip to main content

All Questions

2 votes
1 answer
68 views

How to use validators in pydantic for default values in combination with ORM mode?

I'm using SQLAlchemy ORM models alongside Pydantic models in a FastAPI context. Currently, I have: class CustomerModel(Base): __tablename__ = "customers" id: Mapped[UUID] = ...
Bram's user avatar
  • 141
0 votes
0 answers
30 views

SqlAlchemy polymorphic with Pydantic TypeAdapter

I have the next models: class A(Base): some_attr: Mapped[str] class B(A): problematic_attr: Mapped[CustomPydanticModel | None] = mapped_column(PydanticType(CustomPydanticModel), ...
Juan Pablo Poittevin's user avatar
2 votes
1 answer
70 views

SQLAlchemy Enum: Combine Shared and Service-Specific Operations Dynamically

I have 2 different apps "Steam" and "Gasoline", this two classes has their unique operations but they also should have shared operations from a monorepo. BaseOperation: "...
hhilal's user avatar
  • 143
1 vote
1 answer
97 views

How to manage Generic Template class inheriting from another Generic class in Python

I'm trying to make a generic Pydantic Schema/SQlAlchemy Model repository using template/Generic Classes but with two stage of inheritance First stage is to have a GenericSchemaRepository with Generic ...
Hervé LE BARS's user avatar
-1 votes
1 answer
142 views

How to query a table that has a many to many relationship using SQLAlchemy, FastAPI, Pydantic, Postgres and field that is a Mapped[List[Obj]]?

I have been going at this for 4 days and I really need some help. As Discussed in the title, I am using Python, SQLAlchemy, PostgreSQL, FastAPI, and Pydantic ( among other things ). I am getting ...
MStudley's user avatar
1 vote
1 answer
123 views

Why is SQLAlchemy / Pydantic auto-loading relations only sometimes and not always?

I have a weird issue in my FastAPI-based application using SQLAlchemy and Pydantic with a Postgres-Database. A User-Model contains two different 1-to-Many-relationships. For unknown reasons, the first ...
delete's user avatar
  • 19.2k
0 votes
0 answers
56 views

How to use Pydantic types with sqlalchemy and asyncpg

Using: Sqlalchemy 1.4 & Pydantic v1 Sqlalchemy + asyncpg query: async def get_api_key( db_session: AsyncSession, api_key_id: ApiKeyId, ) -> ApiKey | None: if api_key_id is None and ...
Prime's user avatar
  • 225
7 votes
2 answers
971 views

Handling Circular Imports in Pydantic models with FastAPI

I'm developing a FastAPI application organized with the following module structure. ... │ ├── modules │ │ ├── box │ │ │ ├── routes.py │ │ │ ├── services.py │ │ │ ├── models.py #...
Biowav's user avatar
  • 311
1 vote
0 answers
190 views

Converting SQLAlchemy models to Pydantic model

I have the following structure of folders: app/ ├── __init__.py ├── database/ │ ├── __init__.py │ └── models/ │ ├── __init__.py │ ├── author.py │ └── book.py ├── schemas/ │ ├── ...
Igor Mendes's user avatar
-1 votes
1 answer
167 views

SQLAlchemy+FastAPI: Set up a relationship in model.py to match a return Pydantic Union in schemas

I have been reading post after post on StackOverflow for a solution to this problem but I haven't been able to find one (maybe someone has a link?) as well as reading the SQLAlchemy/FastAPI/Pydantic ...
Yoili Youth's user avatar
2 votes
0 answers
133 views

Problem with circular Relashionship in async SQLAlchemy

I have the following sqlalchemy structure for some objects: from typing import Optional from sqlalchemy import ForeignKey, Integer from sqlalchemy.orm import DeclarativeBase, mapped_column, ...
Кирилл Сыроежкин's user avatar
0 votes
1 answer
91 views

Pydantic forces SQL query to already populated field

I have interesting case happening with Pydantic: even though the field is already populated by object, when FastAPI returns (or I manually use model_validate) the extra SQL is called to some fields (...
Miradil Zeynalli's user avatar
0 votes
0 answers
87 views

How to validate SQLAlchemy session.execute(stmt).scalars().all() result using by Pydantic model

@router.get("/get_in_list/", status_code=status.HTTP_200_OK, response_model=LanguageModelResponse) async def get_language_list( label: Optional[str], session: AsyncSession = Depends(...
Сергей Севастьянов's user avatar
0 votes
0 answers
65 views

Pydantic validation error for a value that cannot be None. It is none

I get this error: Value error, Status cannot be None [type=value_error, input_value=<JobStatus.PENDING: 'PENDING'>, input_type=JobStatus] on the from_orm method of this class: ""&...
wachichornia's user avatar
  • 1,188
1 vote
1 answer
1k views

When using SQLModel and Pydantic create_model how do you specify the database schema and tablename?

I have the code below working to use a dictionary to dynamically create a model and database table. However I'm am struggling to figure out how to specify the tablename and database schema that it ...
configure.ng's user avatar

15 30 50 per page
1
2 3 4 5
12