Skip to content
Advertisement

Tag: sqlalchemy

Using SQLAlchemy 1.4 classical / imperative mapping style?

I am using the clean architecture & TDD development method in my Python project. Updating from SQLAlchemy 1.3 to SQLAlchemy 1.4 broke the ability to test against an in-memory Postgres DB, and I can’t find how to fix the problem. Following DDD principles, the project uses the new imperative mapping syntax which replace classical mapping declarations. Here is a minimal

Trying to use SQLAlchemy relationships

As an example, I have a cities table and a movie theaters table. A city has multiple movie theaters so: now i want to get all theaters for a city: This query throws error: not sure what I’m doing wrong? Answer Something like this should automatically do the join for you: And then the query would be Make sense?

SQLAlchemy SQL expression with JSONB query

I have the following property on a flask-sqlalchemy model. I want to make this approved_at property a sortable column in flask-admin, but apparently I need to convert this to a hybrid property using SQL expressions. I don’t know how to convert this query into a sqlalchemy SQL expression, since it’s pretty complex with the JSONB query in it. I’ve looked

Self-referencing many-to-many relationship with an association object in SQLAlchemy

I’ve found examples for a self-referencing many-to-many relationship with an association table. How can I achieve the same using an association object? The code below is based on: How can I achieve a self-referencing many-to-many relationship on the SQLAlchemy ORM back referencing to the same attribute? Answer The following approach uses an association object instead of an association table to

Validation error while inputting a record into Postgres

I have created a table using the following query, Following is my models.py Following is my schema.py I use the following code to create an user, The problem is that I’m getting the following error, raise ValidationError(errors, field.type_) pydantic.error_wrappers.ValidationError: 1 validation error for AccountsInfo response -> created_on str type expected (type=type_error.str) what am I missing? Answer raise ValidationError(errors, field.type_) pydantic.error_wrappers.ValidationError:

Advertisement