SQLAlchemy + SQL Injection

What are the best practices for mitigating SQL injection attacks when using SQLAlchemy?

SqlAlchemy - Filtering by Relationship Attribute

I don't have much experience with SQLAlchemy and I have a problem, which I can't solve. I tried searching and I tried a lot of code. This is my Class (reduced to the most significant code): class...

How to improve SQLAlchemy performance?

I made a client application that uses HTTP to communicate with a Python 2 server using a simple API. The server uses SQLAlchemy's ORM quite extensively to serve the data for those HTTP requests....

How to monitor/log sqlalchemy scoped sessions?

I am working on a legacy application that uses SqlAlchemy and whose architecture is...well...suboptimal. I recently discovered there is a lot of (unneeded) mysql connections openned by the...

Performing union with three queries - SQLAlchemy

In my project setup querying is being done based on the SQLAlchemy. As per my previous requirements I have done the union with two queries. Now I need to do Union with three queries. Code is as...

How to combine py.test fixtures with Flask-SQLAlchemy and PostgreSQL?

I'm struggling to write py.test fixtures for managing my app's database that maximize speed, supports pytest-xdist parallelization of tests, and isolates the tests from each other. I'm using...

SQLAlchemy events are not working

I'm working with SQLAlchemy and tried to add events to my code. While everything works, the events are not being triggered. Here is my simplified code: from sqlalchemy import Column, String from...

Create ORM object from dict and add to session

Let's say I have a User model with attributes id, name, email and a relationship languages. Is it possible to create a User instance from existing data that behaves like I would have queried it...

SQLAlchemy automap: Best practices for performance

I'm building a python app around an existing (mysql) database and am using automap to infer tables and relationships: base = automap_base() self.engine = create_engine( ...

Integrating Swagger/OpenAPI generated python server with existing Flask application

I am interested in integrating a swagger-codegen generated Python server with an existing Flask application. swagger-codegen generates a Python implementation based on the Connexion library from...

How to use encrypted password in connection string of sqlalchemy?

I'm working with sqlalchemy and oracle, but I don't want to store the database password directly in the connection string, how to store a encrypted password instead?

AttributeError: __enter__ using with statement SqlAlchemy session

I'm getting this AttributeError: __enter__ when I try to use SQLAalchemy session like in this guide. My code: Session = scoped_session(sessionmaker(autoflush=True, autocommit=False,...

Get Primary Key column name from table in sqlalchemy (Core)

I am using the core of Sqlalchemy so I am not using a declarative base class like in other similar questions. How to get the primary key of a table using the engine?

How to make sure the query run with read-only action on MySQL/PostgreSQL database?

Precondition: The database is running at somewhere without of my control, but I have the authorization account to connect the database. I need to make sure all queries running through my...

AttributeError: 'generator' object has no attribute 'to_sql' While creating datframe using generator

I am trying to create a datafrmae from fixedwidth file and load into postgresql database. My input file is very huge (~16GB) and 20Million records. So if i create dataframe it is consuming most of...

Connecting to MSSQL in Flask using Flask-SQLAlchemy and pyodbc

I am not able to connect to MSSQL Server 2016 database using Flask-SQLALchemy and pyodbc. I have searched through Google and none of the solutions work. I am getting the following...

How to fix SQLAlchemy connection problem: 'Connection info needed in SQLAlchemy format' when connecting to IBM db2 server hosted on IBM Cloud

So, I've been trying to connect to the IBM DB2 server hosted on IBM cloud for the past few days and managed to connect to it using the provided credentials and the 'ibm_db', 'ibm_db_sa', and the...

flask db init Error: Could not import "app.run"

I am trying to initialise my db, and everytime i run the flask db init command, I get that error. I am unsure why, my FLASK_APP and FLASK_ENV are set correctly. I have been reorganising the...

sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1054, "Unknown column 'detail.id' in 'field list'")

I set up a small website, where anyone can store 'name,email,phone' but when I retrieve data from database so I'm getting this error. I don't why? I'd spend two days to resolve this error but...

I have installed python-dotenv but python cannot find it

i am using dotenv in a flask project, and have also tested this in a dumbed down test environment as well. I have tried uninstalling and reinstalling etc but the dotenv module cannot be found by...

SQLAlchemy connection error with Db2 on IBM Cloud

I've been trying to connect to the IBM DB2 server hosted on IBM cloud using the provided credentials. I followed the instruction but i received following error : Connection info needed in...

TypeError: No matching overloads found for java.util.Properties.setProperty(str,str)

I was trying to connect to an athena database with PyAthenaJDBC. I was looking for some information about how to do this and I trid this code: import contextlib from urllib.parse import quote_plus...

Nginx web app redirect fails on form submission (redirects to bogus url with %2C in it)

First up, I am new to most of this. I am running a Flask app on a remote (Linode) Ubuntu server. The app is served with Gunicorn and Nginx. After a recent update, redirects began behaving oddly...

"psycopg2.errors.UndefinedTable: relation "flights" does not exist"

import os from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker engine = create_engine("postgres://kali:[email protected]/mydb") db =...

How to differentiate causes of SQLAlchemy's IntegrityError?

SQLAlchemy appears to just throw a general IntegrityError when there is a data integrity problem with a transaction. Of course, the exact query and error message are contained in the exception,...

Fastapi sqlalchemy pydantic relational field

I am just a starter in FastAPI/Pydantic & SqlAlchemy - I have two model Post and Category where I want Post should fetch Category name instead of only id when I try to use the below code it gives...

ERROR: Failed building wheel for psycopg2 (Ubuntu 20.04 + Python 3.8.5 + venv)

Greetings wisdom from Stackoverflow! I'm having issues building wheel for psycopg2 thru pip install -r requirements.txt. I'm on ubuntu 20.04 + python 3.8.5 + venv. This is my...

Flask-Mail [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)

I'm developing a Flask application that implements a user registration system. The application uses Flask-Mail and itsdangerous to confirm a user's registration and reset their password via email....

SQLAlchemy object Session AttributeError: __enter__

SQLAlchemy session not working when I use it inside a with statement. It should work, since the sessionmaker returns a Session object that according to the source code does have __enter__ and...

FastAPI User Authentication with verification Email

I am creating the User Authentication API route that is able to register the user if it is not already registered in the database and if an email address is in the database it will alert the user...