On Tue, Aug 23, 2022, at 1:50 PM, Evgenii wrote: > Hi there! > > > > Please help me to understand: > I want to make two equal queries, that sends real queries to database each > time: > > > `session.query(InstrumentTable).get(instr_id) > <some other code> > session.query(InstrumentTable).get(instr_id) ` > > > The problem is that second query returns instance from identity_map. > I know how to hardcode it, but I want a beautiful solution. > > > 1. No, I cannot use refresh method, because it is not vectorized > (this part of code is used in custom vectorized refresh method, > because in our case each transaction is slow and therefore expensive) - > having vectorized SA refresh is a perfect solution, but it does not exist.
"vectorized". googled it, seems to mean "Vectorization is the process of converting an algorithm from operating on a single value at a time to operating on a set of values at one time. " OK. which would mean that get() is also not "vectorized" since it also operates on one value at a time...so..not really sure what that means. Anyway, don't use query.get(), use session.get() and pass populate_existing https://docs.sqlalchemy.org/en/14/orm/session_api.html?highlight=session+get#sqlalchemy.orm.Session.get session.get(InstrumentTable, id, populate_existing=True) > 1. rollback make real second query, but it seems to be hardcode. > 2. session.identity_map._dict = {} hardcode too > 3. Opening another session hardcode too. > 4. Using one of AUTOCOMMIT, READ COMMITTED, READ UNCOMMITTED, > REPEATABLE READ, SERIALIZABLE as isolation_level seems to be a true way, > but none of them does not work as I expect. > > > > -- > 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 view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/0808aeb1-e32d-4a42-bac2-959ee6d03ba7n%40googlegroups.com > > <https://groups.google.com/d/msgid/sqlalchemy/0808aeb1-e32d-4a42-bac2-959ee6d03ba7n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/9ba2557f-9fb5-4e59-9af8-30701de9896e%40www.fastmail.com.
