Clinical-Genomics / chanjo

Chanjo provides a better way to analyze coverage data in clinical sequencing.
https://clinical-genomics.github.io/chanjo/
MIT License
49 stars 12 forks source link

Unfreeze SQLAlchemy #252

Closed dnil closed 3 months ago

dnil commented 4 months ago

This PR adds | fixes:

How to prepare for test:

How to test:

-

Expected outcome:

Review:

This version is a:

dnil commented 4 months ago

Mm, yes, but this is only to 1.4 so far. If you dont mind I would like to enable move-to-2.0-warnings and see what gives. From the changelog its also evident we have actually already been higher than 1.3, although its not super clear what version we were on..

northwestwitch commented 4 months ago

Mm, yes, but this is only to 1.4 so far. If you dont mind I would like to enable move-to-2.0-warnings and see what gives. From the changelog its also evident we have actually already been higher than 1.3, although its not super clear what version we were on..

With SQLAlchemy 1.4 you can try creating a "future" engine, something that resembles SQLAlchemy 2. Perhaps this would help? --> https://docs.sqlalchemy.org/en/14/core/future.html

dnil commented 4 months ago

Well, yes, I tested with

SQLALCHEMY_WARN_20=1 pytest tests/

It gives a few, but it looks like only a few functions. I suspect the calculate -> add_columns will be the most annoying..

../../../../usr/local/miniconda3/envs/scout38again/lib/python3.8/site-packages/alchy/model.py:421
  /usr/local/miniconda3/envs/scout38again/lib/python3.8/site-packages/alchy/model.py:421: MovedIn20Warning: The ``declarative_base()`` function is now available as sqlalchemy.orm.declarative_base(). (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    Model = declarative_base(cls=Base,

../../../../usr/local/miniconda3/envs/scout38again/lib/python3.8/site-packages/_pytest/config/__init__.py:1448
  /usr/local/miniconda3/envs/scout38again/lib/python3.8/site-packages/_pytest/config/__init__.py:1448: PytestConfigWarning: Unknown config option: looponfailroots

    self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")

tests/cli/test_cli_calculate.py: 16 warnings
tests/cli/test_cli_load.py: 20 warnings
tests/cli/test_cli_store.py: 69 warnings
tests/store/test_store_api.py: 81 warnings
tests/test_calculate.py: 32 warnings
  /usr/local/miniconda3/envs/scout38again/lib/python3.8/site-packages/alchy/session.py:31: SADeprecationWarning: Use .persist_selectable (deprecated since: 1.3)
    info = getattr(mapper.mapped_table, 'info', {})

tests/cli/test_cli_store.py::test_remove
  /Users/dannil/sandbox/chanjo/tests/cli/test_cli_store.py:32: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    assert Sample.query.get(sample_id)

tests/cli/test_cli_store.py::test_remove
tests/cli/test_cli_store.py::test_remove
  /Users/dannil/sandbox/chanjo/chanjo/cli/db.py:40: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    sample_obj = Sample.query.get(sample_id)

tests/cli/test_cli_store.py::test_remove
  /Users/dannil/sandbox/chanjo/tests/cli/test_cli_store.py:37: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    assert Sample.query.get(sample_id) is None

tests/cli/test_cli_store.py::test_samples
  /Users/dannil/sandbox/chanjo/tests/cli/test_cli_store.py:52: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    assert Sample.query.get(sample_id)

tests/cli/test_cli_store.py::test_transcripts
  /Users/dannil/sandbox/chanjo/tests/cli/test_cli_store.py:78: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    assert Sample.query.get(sample_id)

tests/cli/test_cli_store.py::test_delete
  /Users/dannil/sandbox/chanjo/tests/cli/test_cli_store.py:105: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    assert Sample.query.get(sample_id)

tests/cli/test_cli_store.py::test_delete
  /Users/dannil/sandbox/chanjo/tests/cli/test_cli_store.py:113: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    assert Sample.query.get(sample_id) is None

tests/cli/test_cli_store.py::test_delete_group
  /Users/dannil/sandbox/chanjo/tests/cli/test_cli_store.py:121: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    assert Sample.query.get(sample_id)

tests/cli/test_cli_store.py::test_delete_group
  /Users/dannil/sandbox/chanjo/tests/cli/test_cli_store.py:129: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    assert Sample.query.get(sample_id) is None

tests/store/test_store_api.py::test_save
  /Users/dannil/sandbox/chanjo/tests/store/test_store_api.py:36: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    assert Sample.query.get(sample_id) == new_sample

tests/store/test_store_api.py::test_save
  /Users/dannil/sandbox/chanjo/chanjo/store/api.py:120: SAWarning: New instance <Sample at 0x7fcb29a117f0> with identity key (<class 'chanjo.store.models.Sample'>, ('ADM12',), None) conflicts with persistent instance <Sample at 0x7fcb29a11730>
    self.commit()

tests/store/test_store_api.py::test_save
  /Users/dannil/sandbox/chanjo/tests/store/test_store_api.py:49: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    assert Sample.query.get(new_sampleid)

tests/test_calculate.py::test_gene
  /Users/dannil/sandbox/chanjo/chanjo/calculate.py:30: SADeprecationWarning: Query.add_column() is deprecated and will be removed in a future release.  Please use Query.add_columns() (deprecated since: 1.4)
    self.mean()
dnil commented 4 months ago

Ah, no, this will be the most annoying, since its actually not in our codebase.. 😞

../../../../usr/local/miniconda3/envs/scout38again/lib/python3.8/site-packages/alchy/model.py:421
  /usr/local/miniconda3/envs/scout38again/lib/python3.8/site-packages/alchy/model.py:421: MovedIn20Warning: The ``declarative_base()`` function is now available as sqlalchemy.orm.declarative_base(). (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    Model = declarative_base(cls=Base
dnil commented 4 months ago

Ok, that was useful on some level I suppose. I'm now fairly convinced we will not be able to use Alchy (final version 2.2.2) with SQLAlchemy>=2. 1.4 seems ok if we wish to go through the hassle; it might help a little somewhere, but it is not going to take us to higher versions of e.g. Flask-SQLAlchemy that we would like.