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') 
  • Can you describe the essence of the problem? What exactly does not work? - MaxU
  • Change the user role for connecting to the database after creating a session using ORM, without creating a new connection to the database. The goal is to use the rights to rows / columns directly in the database. In the example above, SQLAlchemy Core is used. - Tihon pm

0