can you add these assertions to env.py?
with context.begin_transaction():
assert not context.get_context()._in_external_transaction
assert not connection.in_transaction()
context.run_migrations()
that's the condition necessary for begin_transaction() to call commit() at the
end.
On Sun, Jan 15, 2023, at 8:57 AM, Mike Bayer wrote:
> It's not supposed to have this problem with a clean env.py. If you were
> running commands on the connection() ahead of calling
> context.begin_transaction(), that would explain things but I dont see that in
> your example.
>
> short answer call connection.commit() at the end of the block , however that
> should not be needed with a plain env.py as you have. so we'd like to know
> what is happening in this example (or if alembic is just broken and despite
> all my testing I am somehow missing something basic)
>
> On Sun, Jan 15, 2023, at 5:34 AM, Lele Gaifax wrote:
>> Hi all,
>>
>> I'm in the process of upgrading another app to SA 2, and got no suprises
>> in the process: everything works smooth and all tests pass.
>>
>> Going one step further, implementing a requested feature that involves a
>> database migration, I'm facing a show stopper, probably due to a silly
>> oversight of mine that already took a couple of hours of investigation:
>> the final step of the "alembic upgrade" is invariably a "ROLLBACK",
>> instead of a "COMMIT":
>>
>> UPDATE alembic_version SET version_num='aa0288cff765' WHERE
>> alembic_version.version_num = '1e49ee0210d7'
>> ROLLBACK
>>
>> Simply downgrading SA to 1.4.46, without any other change, "fixes" the
>> issue and the migration ends with a "COMMIT" as expected.
>>
>> The Alembic environment
>>
>> https://gitlab.com/metapensiero/SoL/-/blob/master/alembic/env.py
>>
>> is rather old being the same as when I started using Alembic in this
>> project (ten years, omg!), but even modernizing it using Alembic 1.9.2
>> template didn't help: when the connection is closed, either explicitly
>> by the old try:finally: code or implicitly by the new
>> connectable.connect() context manager, a ROLLBACK is issued.
>>
>> Do you have an hint on what I'm missing?
>>
>> Thanks in advance,
>> bye, lele.
>> --
>> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
>> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
>> [email protected] | -- Fortunato Depero, 1929.
>>
>> --
>> 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]
>> <mailto:sqlalchemy%[email protected]>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sqlalchemy/87h6wsdr1y.fsf%40metapensiero.it.
>>
>
>
>
> --
> 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/c1edf82e-2051-4e32-b346-1136acfb1124%40app.fastmail.com
>
> <https://groups.google.com/d/msgid/sqlalchemy/c1edf82e-2051-4e32-b346-1136acfb1124%40app.fastmail.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/79dac31b-500d-4d47-bb69-baae033d7ba5%40app.fastmail.com.