You need to correctly implement a method that allows you to specify a user when using ORM. Those. when executing the query, call the SET ROLE , SET SESSION AUTHORIZATION , or EXECUTE AS depending on the database.
How to implement role management in web applications correctly, provided that each user has his own role in the database? How to change the user for the next transaction after connecting to the database?
import sqlalchemy as sa from dbviews import list_account_settings engine = sa.create_engine('postgres://wepapp@localhost') with engine.connect() as conn: conn.execute('SET ROLE user12345') conn.transaction(list_account_settings) conn.execute('RESET ROLE')