SQLAlchemy 2.0 support

22 views
Skip to first unread message

zsol...@gmail.com

unread,
Nov 24, 2022, 1:38:01 PM11/24/22
to pylons-discuss
Hi,

I'm starting a new project from cookiecutter and I wanted to use SQLAlchemy 2.0 (pre-release currently). 

So far I changed meta.py to 

class Base(DeclarativeBase):
    metadata = my_metadata

as well as changing the model to the new Mapped / mapped_column syntax.

My question is that is there anything in pyramid_tm, transaction or zope.sqlalchemy packages which needs to be changed, or this was all I needed?

SQLAlchemy changed a lot in 2.0, that's why I think the whole transaction related part might be affected.

If it's the case then I'll just go back to 1.4 and wait a year or so till it matures. What do you think?

Zsolt




Michael Merickel

unread,
Nov 24, 2022, 2:39:39 PM11/24/22
to pylons-...@googlegroups.com
I'm unaware of any incompatibilities with SQLAlchemy 2.0 after reading the upgrade guide pretty extensively when I upgraded to 1.4. Nothing stood out in the changes to me that wouldn't work well with the existing pyramid_tm pattern.

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/7db23f68-cdef-42e4-8b71-3279c4db1c61n%40googlegroups.com.

zsol...@gmail.com

unread,
Nov 27, 2022, 5:38:05 AM11/27/22
to pylons-discuss
Thanks, it seems to work so far. Basically the 3 line changes in meta.py were all what was needed. AFAIK even this is not critical, just needed for the mypy typings help.

Jonathan Vanasco

unread,
Nov 27, 2022, 1:02:33 PM11/27/22
to pylons-discuss
There was one potential incompatibility with transaction, but the zope.sqlalchemy team addressed it already ( see https://github.com/zopefoundation/zope.sqlalchemy/issues/60 ).  There are deprecation warnings that are still unhandled ( see https://github.com/zopefoundation/zope.sqlalchemy/pull/64 ) but everything else should be fine.

Most of the 2.0 sqlalchemy changes are in the engine and query systems, and pretty isolated from the support the cookiecutter and zope.sqlalchemy provide.

Zsolt Ero

unread,
Nov 27, 2022, 1:23:21 PM11/27/22
to pylons-...@googlegroups.com
Great to know! About the warnings, I'm on 2.0 and it works, so either some of those RemovedIn20Warning are not removed or none of them are left.

I mean I rewrote my queries to 2.0 style, but I've read that 1.x style queries will continue to work, they are just removed from the documentation now.

For cookiecutter I recommend changing to using DeclarativeBase and Mapped + mapped_column in the model, once 2.0 is released.

Zsolt





--
You received this message because you are subscribed to a topic in the Google Groups "pylons-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pylons-discuss/sDMJlpQQedM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pylons-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/bb45eb53-c263-4d35-af74-60691ca010d5n%40googlegroups.com.

Jonathan Vanasco

unread,
Nov 28, 2022, 1:53:28 PM11/28/22
to pylons-discuss
On Sunday, November 27, 2022 at 1:23:21 PM UTC-5 zsol...@gmail.com wrote:
Great to know! About the warnings, I'm on 2.0 and it works, so either some of those RemovedIn20Warning are not removed or none of them are left.

The warnings are still there, you most likely have fully compatible code. Congrats!

One small thing to look out for: SqlAlchemy does some extra stuff now to make sure warnings are visible.  I don't think zope.sqlalchemy or many other projects do this.  TLDR: Python started to hide "warnings" around 2010, and you need to opt-in to seeing them. This caused many issues with SqlAlchemy, because the "postgres" driver name had been deprecated for 10+ years but people were still using it because they missed the "warnings".  

I mean I rewrote my queries to 2.0 style, but I've read that 1.x style queries will continue to work, they are just removed from the documentation now.

Yes.  AFAIK, there is no planned deprecation for it.  Mike re-wrote the tutorial for 2.0 and we had a few people help out in older docs to remove all the 1.x query instructions.  IIRC, they should still be around in the FAQ and some various docs for legacy troubleshooting, but there is a decision for all new development to happen in the 2.0 API style and to help people migrate to the new syntax.

Zsolt Ero

unread,
Nov 28, 2022, 4:14:16 PM11/28/22
to pylons-...@googlegroups.com
I just use "PYTHONWARNINGS=default", afaik that's all I need to do right? It shows me all the Pyramid and waitress warnings.



--
You received this message because you are subscribed to a topic in the Google Groups "pylons-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pylons-discuss/sDMJlpQQedM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pylons-discus...@googlegroups.com.

Jonathan Vanasco

unread,
Nov 29, 2022, 12:31:39 PM11/29/22
to pylons-discuss
That should be fine.  If you see any warnings, that's unfortunately more than most developers see!
Reply all
Reply to author
Forward
0 new messages