Closed RalfG closed 3 months ago
Hi @RalfG, thanks for the patch! I'm fine with it but I'm a bit confused that I don't see these warnings with the latest SQLAlchemy, nor with the latest pre-2.0 version. Not sure if I'm missing something, but there is a different set of unimod warnings in my tests over here.
Also, if the import works, then how do expect to catch an ImportError
? Or is it for some future version?
Not sure why the warning only shows up sometimes. I still have it in more recent test runs:
../../../../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pyteomics/mass/unimod.py:53
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pyteomics/mass/unimod.py:53: MovedIn20Warning: The ``declarative_base()`` function is now available as sqlalchemy.orm.declarative_base(). (deprecated since: 2.0) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
Base = declarative_base(metaclass=SubclassRegisteringDeclarativeMeta)
https://github.com/compomics/psm_utils/actions/runs/8454522238/job/23159731768#step:7:36
Also, if the import works, then how do expect to catch an ImportError? Or is it for some future version?
The original location was deprecated in 2.0, so I expect there to be ImportErrors in future versions.
Thank you @RalfG !
It seems like SQLAlchemy has a convoluted decorator system responsible for those warnings, and so this particular warning is not emitted at import time, rather at call time. Also, the default Python warning filters ignore this warning, which is why I wasn't able to see it at all outside of pytest
.
I will just merge the PR now, thank you for contributing!
In sqlalchemy version 2.0,
declarative_base
andDeclarativeMeta
moved to another module. This adds a try-except around the imports to retain compatibility with sqlalchemy <2.0 and >2.0. Before, the import still worked, but resulted inMovedIn20Warning
(for example: https://github.com/compomics/psm_utils/actions/runs/6239222484/job/16936699966?pr=50#step:7:35)