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

Add support for SQLAlchemy 1.4 #391

Merged
merged 19 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d64ecc9
SA14/CI: Add SQLAlchemy 1.4 to the test matrix
amotl Nov 16, 2020
1d9e151
SA14: Add `get_view_names` method to SQLAlchemy dialect
amotl Dec 18, 2020
62fd182
SA14: Add SQLAlchemy 1.4 compatibility for CrateCompiler
amotl Nov 16, 2020
bcf9fff
SA14: Adjust CrateDB dialect compiler patch to SqlAlchemy 1.4.36
amotl May 11, 2022
9369158
SA14: Adjust `rewrite_update` parameter mangling
amotl May 11, 2022
867a4c0
SA14/Tests: Fix call signature to match `reflection.Inspector.get_tab…
amotl May 12, 2022
9ecb35d
SA14/Tests: Do not pass `params=None` to `crate_before_execute`
amotl May 12, 2022
071beac
SA14/Tests: Declare column expressions for `_score` as `literal_column`
amotl May 12, 2022
e58a657
SA13: Suppress specific LGTM.com warning
amotl May 13, 2022
40b697e
SA14: Add test cases for new dialect method `get_view_names`
amotl May 17, 2022
0e5b785
SA14: Enable SQL compilation caching for CrateDialect and friends
amotl May 17, 2022
ca33c73
SA14/Tests: Remove masking the resultproxy and fix setup of fake cursors
amotl May 18, 2022
a48c093
SA14: Fix SQLAlchemy deprecation warning on `before_execute` event hdlr
amotl May 18, 2022
40cabe3
SA14: Final adjustments to the changelog
amotl May 18, 2022
abc6a6a
SA14: Add test fixture for testing VIEWs
amotl May 24, 2022
35aa890
Documentation: Minor edit to fix link checker
amotl May 25, 2022
14479e5
SA14: Improve inline documentation of CrateDB dialect compiler
amotl Jun 1, 2022
d93dfce
SA14/CI: Update to SQLAlchemy 1.4.37
amotl Jun 1, 2022
aad1458
SA14/CI: Suppress alert from lgtm.com
amotl Jun 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
os: [ubuntu-latest, macos-latest]
python-version: ['3.7', '3.8', '3.9', '3.10']
cratedb-version: ['4.8.0']
sqla-version: ['1.3.24']
sqla-version: ['1.3.24', '1.4.37']
fail-fast: true

steps:
Expand Down
37 changes: 37 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,43 @@ Unreleased
- Added support for enabling SSL using SQLAlchemy DB URI with parameter
``?ssl=true``.

- Added support for SQLAlchemy 1.4

.. note::

For learning about the transition to SQLAlchemy 1.4, we recommend the
corresponding documentation `What’s New in SQLAlchemy 1.4?`_.



Breaking changes
----------------

Textual column expressions
''''''''''''''''''''''''''

SQLAlchemy 1.4 became stricter on some details. It requires to wrap `CrateDB
system columns`_ like ``_score`` in a `SQLAlchemy literal_column`_ type.
Before, it was possible to use a query like this::

session.query(Character.name, '_score')

It must now be written like::

session.query(Character.name, sa.literal_column('_score'))

Otherwise, SQLAlchemy will complain like::

sqlalchemy.exc.ArgumentError: Textual column expression '_score' should be
explicitly declared with text('_score'), or use column('_score') for more
specificity


.. _CrateDB system columns: https://crate.io/docs/crate/reference/en/4.8/general/ddl/system-columns.html
.. _SQLAlchemy literal_column: https://docs.sqlalchemy.org/en/14/core/sqlelement.html#sqlalchemy.sql.expression.literal_column
.. _What’s New in SQLAlchemy 1.4?: https://docs.sqlalchemy.org/en/14/changelog/migration_14.html


2020/09/28 0.26.0
=================

Expand Down
7 changes: 6 additions & 1 deletion DEVELOP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ Run all tests::

Run specific tests::

# Ignore all tests below src/crate/testing
./bin/test -vvvv -t SqlAlchemyCompilerTest
./bin/test -vvvv -t test_score
./bin/test -vvvv -t sqlalchemy

Ignore specific test directories::

./bin/test -vvvv --ignore_dir=testing

You can run the tests against multiple Python interpreters with tox_::
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Prerequisites
=============

Recent versions of this library are validated on Python 3 (>= 3.7).
It might also work on earlier versions of Python.
It may also work on earlier versions of Python.


Installation
Expand Down
5 changes: 2 additions & 3 deletions docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ Learn how to install and get started the :ref:`CrateDB Python client library
Prerequisites
=============

Python 3.7 is recommended.

However, :ref:`older versions of Python <python-versions>` can still be used.
Recent versions of this library are validated on Python 3 (>= 3.7).
It may also work on earlier versions of Python.

`Pip`_ should be installed on your system.

Expand Down
2 changes: 1 addition & 1 deletion docs/sqlalchemy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The CrateDB Python client library provides support for SQLAlchemy. A CrateDB
configuration.

The CrateDB Python client library is validated to work with SQLAlchemy versions
``1.3``.
``1.3`` and ``1.4``.

.. NOTE::

Expand Down
12 changes: 12 additions & 0 deletions lgtm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
queries:

# Suppress some LGTM warnings.

# A module is imported with the "import" and "import from" statements.
# https://lgtm.com/rules/1818040193/
- exclude: py/import-and-import-from
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work? #391 (comment)

Copy link
Member Author

@amotl amotl Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't ;[. At least, it does not work while not being merged. I hope that the additional rule will be recognized after the merge. However, it is weird because the other rule about py/not-named-self apparently seems to work well.


# Disable rule to compensate parameter naming in `CrateCompiler._get_crud_params`.
# Using an alternative name for the first parameter of an instance method makes code more difficult to read.
# https://lgtm.com/rules/910082/
- exclude: py/not-named-self
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def read(path):
test=['zope.testing>=4,<5',
'zc.customdoctests>=1.0.1,<2',
'stopit>=1.1.2,<2'],
sqlalchemy=['sqlalchemy>=1.0,<1.4', 'geojson>=2.5.0']
sqlalchemy=['sqlalchemy>=1.0,<1.5', 'geojson>=2.5.0']
),
python_requires='>=3.4',
install_requires=requirements,
Expand Down
5 changes: 2 additions & 3 deletions src/crate/client/doctests/sqlalchemy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ the other rows. The higher the score value, the more relevant the row.
In most cases ``_score`` is not part of the SQLAlchemy Table definition,
so it must be passed as a string::

>>> session.query(Character.name, '_score') \
>>> session.query(Character.name, sa.literal_column('_score')) \
... .filter(match(Character.quote_ft, 'space')) \
... .all()
[('Tricia McMillan', ...)]
Expand All @@ -298,11 +298,10 @@ To search on multiple columns you have to pass a dictionary with columns
and ``boost`` attached. ``boost`` is a factor that increases the
relevance of a column in respect to the other columns::

>>> from sqlalchemy.sql import text
>>> session.query(Character.name) \
... .filter(match({Character.name_ft: 1.5, Character.quote_ft: 0.1},
... 'Arthur')) \
... .order_by(sa.desc(text('_score'))) \
... .order_by(sa.desc(sa.literal_column('_score'))) \
... .all()
[('Arthur Dent',), ('Tricia McMillan',)]

Expand Down
Loading