On Fri, Jan 11, 2019 at 1:19 PM tonthon <[email protected]> wrote: > > Hi, > > We're using Sqlalchemy in a Pyramid web application, with the pyramid_tm > package (a transaction that wraps every web request inside a DB transaction). > It's very usefull and it works like a charm. > > In order to follow some security rules and to be able to certify part of our > app, we want to change some things : > - For a specific MyModel, the main bind should have only read access. > - Another bind, dedicated to MyModel and only used by a separated library > should have RW privileges. > > The problem comes with the following : > - A "transaction" begins > - A "session1" object is initialized with the Read-only bind > - An "instance1" of MyModel is loaded in "session1" > - A "session2" using a binding with RW privileges is initialized > - It loads a MyModel "instance2" in the "session2" and modifies it (then > merges it) > - "session2" is commited (instance2 is persisted) > - I can't get the "instance1" of MyModel initially loaded to be refreshed > (surely due to the transaction isolation level). > > Has anyone an advice to share on how to refresh "instance1" ?
if these "binds" point to exactly the same database schema and just have different permissions you might find it much easier to use one session with two binds. You can override get_bind() to use a different engine for write operations on a specific model. there's an example of this at: https://techspot.zzzeek.org/2012/01/11/django-style-database-routers-in-sqlalchemy/ . there's also a special hook where you can persist individual instances of a class on different database connections too but you shouldn't need that here. > > Thanks in advance > Best regards > Gaston Tjebbes > http://majerti.fr > > > > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
