Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MyPy support for SQLAlchemy #20484

Open
kaxil opened this issue Dec 23, 2021 · 27 comments
Open

Use MyPy support for SQLAlchemy #20484

kaxil opened this issue Dec 23, 2021 · 27 comments
Assignees
Labels
mypy Fixing MyPy problems after bumpin MyPy to 0.990

Comments

@kaxil
Copy link
Member

kaxil commented Dec 23, 2021

Body

https://docs.sqlalchemy.org/en/14/orm/extensions/mypy.html describes how type checking can be used with SQLAlchemy.

This is possible after we bump the SQLAlchemy version to 1.4+

@kaxil kaxil added the mypy Fixing MyPy problems after bumpin MyPy to 0.990 label Dec 23, 2021
@uranusjr
Copy link
Member

Except we're still on 1.3 😔

@kaxil
Copy link
Member Author

kaxil commented Dec 23, 2021

Yeah :( Which dep is causing us to stay on <1.4, I can't remember anymore

@kaxil
Copy link
Member Author

kaxil commented Dec 23, 2021

#16630

Flask-Appbuilder ... 😢

@potiuk
Copy link
Member

potiuk commented Dec 23, 2021

Ehhhh

@kaxil
Copy link
Member Author

kaxil commented Dec 23, 2021

Actually, it looks like it is because of pallets-eco/flask-sqlalchemy#1001 that FAB has to still use <1.4. FAB Issue: dpgaspar/Flask-AppBuilder#1710

@potiuk
Copy link
Member

potiuk commented Dec 23, 2021

dependency

@kaxil
Copy link
Member Author

kaxil commented Dec 23, 2021

Very apt XKCD 😄

@bmckallagat-os
Copy link
Contributor

@kaxil I noticed they deleted your comment and locked the convo... petition to start an opensource war?

@potiuk
Copy link
Member

potiuk commented Jan 11, 2022

@kaxil I noticed they deleted your comment and locked the convo... petition to start an opensource war?

I started a few already, some of them with success .... some of them ... not yet. Maybe time for another one ;)

@bmckallagat-os
Copy link
Contributor

@kaxil I noticed they deleted your comment and locked the convo... petition to start an opensource war?

I started a few already, some of them with success .... some of them ... not yet. Maybe time for another one ;)

Please, use that Apache clout 🤣

@uranusjr
Copy link
Member

uranusjr commented Jan 12, 2022

I took a look at the code path and tried an alternative fix that does not need to involve the Pallets team (since they do not seem to be interested in supporting this): dpgaspar/Flask-AppBuilder#1783

@boredland
Copy link
Contributor

so isn't this done now via dpgaspar/Flask-AppBuilder#1786 ?

@potiuk
Copy link
Member

potiuk commented Jan 21, 2022

It's in https://pypi.org/project/Flask-AppBuilder/3.4.4rc1/ - so as soon as it's released we will be able to switch to it.

@boredland
Copy link
Contributor

perhaps I am misunderstanding something, but to me it looks like somewhere (didn't find where) there seems to be a hardcoded prefix 'postgres://' for connections. that surely will break after the 1.4. upgrade and would have to be 'postgresql://':
image

@zzzeek
Copy link

zzzeek commented Jan 21, 2022

hi just an FYI, the SQLAlchemy mypy plugin is not going anywhere but in the 2.0 series of SQLAlchemy we hope to have a completely plugin-less approach to typing in place and the mypy plugin itself should become legacy. bugs within the mypy plugin that don't have an easy fix we will likely just "wontfix". so support the plugin sure but don't get too reliant on it.

@potiuk
Copy link
Member

potiuk commented Jan 21, 2022

perhaps I am misunderstanding something, but to me it looks like somewhere (didn't find where) there seems to be a hardcoded prefix 'postgres://' for connections. that surely will break after the 1.4. upgrade and would have to be 'postgresql://': image

Not really. This is "Airflow" connection to connect to Postgres via "postgres provider" - it's not even an SQLAlchemy connection - we are using DBApi there and Postgres Provider exposes plain old "SQL" interface to Postgres Provider (It would be next to impossible to have generic SQLAlchemy ORM interface).

SQLAlchemy is only used for Airlfow's internal meta-data as part of the application.

@saulbein
Copy link

saulbein commented Feb 3, 2022

dpgaspar/Flask-AppBuilder/releases/tag/v3.4.4 the fix has now been released - it would be nice to be able to update sqlalchemy to 1.4 since we have some other dependencies that we would like to update and they require 1.4.

@potiuk
Copy link
Member

potiuk commented Feb 3, 2022

dpgaspar/Flask-AppBuilder/releases/tag/v3.4.4 the fix has now been released - it would be nice to be able to update sqlalchemy to 1.4 since we have some other dependencies that we would like to update and they require 1.4.

We did already - but currently we are dealing with the aftermath of it - there are couple of things that broke even our PRs and main builds and we are a bit scrambling to get the full SQLAlchemy 1.4 compatibility (and FAB 3.4.4 compatibility) in main. This caused persistent failures as well as intermittent flaky tests in our CI builds.

There are many issues: #20874 #19294 #21294 #21296 #21272

Until those are fixed and our main build is stabilized, there is not going to be any work on this one.

BTW. If you want you are most welcome to help with any of the above (see the comments to find out how and if you can help) or even attempt to work on adding MyPy support n Parallel.

@potiuk
Copy link
Member

potiuk commented Feb 6, 2022

@saulbein - maybe you would like to add support for MyPY - seems that most of the problems with SQLAlchemy 1.4 have been addresse,d you could take care about it ?

@bmckallagat-os
Copy link
Contributor

@potiuk Are there any other related issues besides #20874 #19294 #21294 #21296 #21272?

Happy to help but those seem to be all resolved or taken.

@potiuk
Copy link
Member

potiuk commented Feb 10, 2022

go ahead. There is still an issue with going beyond SQLAlchemy 4.1.9 (but It should not clash with mypy support)

@saulbein
Copy link

@potiuk I would like to help, but sadly I don't know much (if at all) about Flask-AppBuilder and can't allocate enough time to learn with other work 😞. I'll see if I can at least contribute some typing.

@bmckallagat-os
Copy link
Contributor

@potiuk I apologize, I just saw this now. I'm going on vacation until the 7th and I will try to tackle this after that time. If anyone wants to assign to themselves, please feel free. Otherwise I will make sure to get this done then.

@potiuk
Copy link
Member

potiuk commented Mar 21, 2022

How about now :) ?

@bmckallagat-os
Copy link
Contributor

@potiuk Finally getting back to this. Just wanted to note that the docs listed in the description state that there will be native type checking without the use of the plugin when 2.0 is released and it is now considered a legacy library.

I'll just add that change however and add a note in the setup.cfg.

@potiuk
Copy link
Member

potiuk commented Apr 13, 2022

Cool

@eladkal
Copy link
Contributor

eladkal commented Mar 6, 2023

https://docs.sqlalchemy.org/en/20/orm/extensions/mypy.html

However, SQLAlchemy 2.0, when released, will feature an all new typing system for ORM Declarative models that removes the need for the Mypy plugin and delivers much more consistent behavior with generally superior capabilities.

I guess we should wait till after we bump to 2.0 (after we completely remove 1.4)? #28723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mypy Fixing MyPy problems after bumpin MyPy to 0.990
Projects
None yet
Development

No branches or pull requests

8 participants