Re: [sqlalchemy] Revert multiple commits using a savepoint

2021-06-21 Thread Simon King
Which version of SQLAlchemy are you using, and how are you creating
your engine? I believe savepoints are handled differently in SA 1.4 if
you are using the "future-style" engine.

Do these doc links help you at all?

https://docs.sqlalchemy.org/en/14/orm/session_transaction.html#nested-transaction

"""
Calling the Session.commit() or Connection.commit() methods will
always commit the outermost transaction; this is a SQLAlchemy 2.0
specific behavior that is reversed from the 1.x series.
"""

https://docs.sqlalchemy.org/en/14/orm/session_transaction.html#session-subtransactions

"""
The “subtransaction” pattern that was often used with autocommit mode
is also deprecated in 1.4. This pattern allowed the use of the
Session.begin() method when a transaction were already begun,
resulting in a construct called a “subtransaction”, which was
essentially a block that would prevent the Session.commit() method
from actually committing.
"""

Simon

On Sat, Jun 19, 2021 at 4:27 PM kaboo HD  wrote:
>
>
> I am trying to test an endpoint in flask and I need to "refresh" the DB after 
> some commits.
>
> The idea I had was something like :
>
> db=SQLAlchemy()
>
> db.session.begin_nested()
>
> db.session.add(Obj)
> db.session.commit()
>
> # some code where last commit is important
>
> db.session.add(Obj2)
> db.session.commit()
>
> # some other code where last commit is important
>
> db.session.rollback()
>
> But it doesn't work unless I have a single commit.
>
> Can you help me please :)
>
> --
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/d77d4621-8f0a-47fd-8e79-ca3de3a4b5edn%40googlegroups.com.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexf7%2Bw7aiSHgcDR5_xenff_m08LTPp%3DyHgGvO-CZu7DREg%40mail.gmail.com.


[sqlalchemy] Revert multiple commits using a savepoint

2021-06-19 Thread kaboo HD

I am trying to test an endpoint in flask and I need to "refresh" the DB 
after some commits.

The idea I had was something like : 

db=SQLAlchemy()

db.session.begin_nested()

db.session.add(Obj)
db.session.commit()

# some code where last commit is important

db.session.add(Obj2)
db.session.commit()

# some other code where last commit is important

db.session.rollback()

But it doesn't work unless I have a single commit. 

Can you help me please :)

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/d77d4621-8f0a-47fd-8e79-ca3de3a4b5edn%40googlegroups.com.