Skip to content

Fix SQLAlchemy warning

Summary

A warning is being raised by SQLAlchemy because we're using a deprecated method.

Steps to reproduce

Run core tests and notice the warnings being raised.

poetry run pytest tests/core/test_sqlite.py

What is the current bug behavior?

9 Warnings are raised.

What is the expected correct behavior?

No warnings should be raised.

Relevant logs and/or screenshots

CI logs: https://gitlab.com/ReubenFrankel/sdk/-/jobs/2151755969#L202

$ poetry run pytest tests/core/test_sqlite.py 
=================================================== test session starts ====================================================
platform darwin -- Python 3.9.9, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /Users/edgarramirez/Code/sdk
plugins: requests-mock-1.9.3
collected 9 items

tests/core/test_sqlite.py .........                                                                                   [100%]

===================================================== warnings summary =====================================================
tests/core/test_sqlite.py::test_sync_sqlite_to_sqlite
tests/core/test_sqlite.py::test_sync_sqlite_to_sqlite
tests/core/test_sqlite.py::test_sync_sqlite_to_sqlite
tests/core/test_sqlite.py::test_sqlite_column_addition
tests/core/test_sqlite.py::test_sqlite_column_addition
tests/core/test_sqlite.py::test_sqlite_column_morph
tests/core/test_sqlite.py::test_sqlite_column_morph
tests/core/test_sqlite.py::test_sqlite_column_no_morph
tests/core/test_sqlite.py::test_sqlite_column_no_morph
  /Users/edgarramirez/Code/sdk/singer_sdk/streams/sql.py:430: SADeprecationWarning: The Engine.has_table() method is
  deprecated and will be removed in a future release.  Please refer to Inspector.has_table(). (deprecated since: 1.4)
    return self._engine.has_table(full_table_name)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================================== 9 passed, 9 warnings in 2.69s ===============================================

Possible fixes

Replace self._engine.has_table(full_table_name) with sqlalchemy.inspect(self._engine).has_table(full_table_name).