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

SQLAlchemy 1.4 support + Move CI to GitHub workflows #506

Merged
merged 59 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
6e11f3f
fix database existence check
bernt-matthias Jul 9, 2020
36e765b
always dispose engine after db existence check
bernt-matthias Jul 9, 2020
743aa21
add docs for postgres_db parameter
bernt-matthias Jul 9, 2020
15dc668
fix dialect_name
bernt-matthias Jul 9, 2020
527b885
optimize execution order
bernt-matthias Jul 9, 2020
37bb37b
database_exists fix return
bernt-matthias Jul 15, 2020
4b396d8
Merge branch 'topic/372-followup' of https://github.com/bernt-matthia…
bernt-matthias Jul 15, 2020
6dd16e7
use None as default
bernt-matthias Jul 15, 2020
7e41e85
break if successful
bernt-matthias Jul 15, 2020
e481582
dispose only for exception
bernt-matthias Jul 15, 2020
74b3513
use Null connection pool and close connections
bernt-matthias Jul 16, 2020
acb681c
fix isort call in tox.ini and import order
bernt-matthias Jul 16, 2020
7908606
rename parameter to databases
bernt-matthias Jul 28, 2020
f509f38
move functions to module level
bernt-matthias Jul 29, 2020
504a92b
Add support for SQLAlchemy 1.4
cnu Dec 25, 2020
0931cae
Fixed errors related to URL.database not being directly settable.
lucventurini Mar 16, 2021
1f09558
Removed the try..except constructs to set the database. Now checking …
lucventurini Mar 17, 2021
6646a47
Cleanups
nsoranzo Mar 17, 2021
1db87e1
Use `execution_options()` method of `Connection`
nsoranzo Mar 17, 2021
36dca77
Merge branch 'topic/372-followup' into sqlalchemy14
nsoranzo Mar 17, 2021
53cf0bc
Lint fixes
nsoranzo Mar 17, 2021
86cf5b2
Move CI lint job to GitHub workflows
nsoranzo Mar 17, 2021
b3d75c3
Testing: drop Python 3.5 and Python 3.9
nsoranzo Mar 17, 2021
4f52578
Use `with engine.connect()` context manager
nsoranzo Mar 18, 2021
57e3f16
Move CI tests from TravisCI to GitHub workflows
nsoranzo Mar 18, 2021
c791211
Add SQLAlchemy 1.3 on Python 3.6 to the test matrix
nsoranzo Mar 18, 2021
36a24eb
Update tests for changes in `create_database`
nsoranzo Mar 18, 2021
151fc8c
Install the version of pg8000 recommended by SQLAlchemy 1.3
nsoranzo Mar 19, 2021
6146a76
Fix another import for SQLAlchemy 1.4
nsoranzo Mar 19, 2021
1c25400
Fix test failing on SQLAlchemy 1.4
nsoranzo Mar 19, 2021
2eecaa9
Fix `AttributeError: 'Query' object has no attribute '_entities'`
nsoranzo Mar 19, 2021
651e380
Fix `AttributeError: type object 'User' has no attribute '_decl_class…
nsoranzo Mar 19, 2021
66dba08
Extend linting to all Python files
nsoranzo Mar 19, 2021
ef10a3e
Fix `AttributeError: 'Query' object has no attribute '_mapper_zero'`
nsoranzo Mar 19, 2021
481245c
Fix `AttributeError: module 'sqlalchemy.orm.mapper' has no attribute …
nsoranzo Mar 19, 2021
7c6ebfe
Fix `make_order_by_deterministic` for SQLAlchemy 1.4
nsoranzo Mar 19, 2021
2563593
Add message to assert
nsoranzo Mar 19, 2021
ebf0c32
Debug test failures under SQLAlchemy 1.4
nsoranzo Mar 22, 2021
dd720c0
Don't mask potential `AttributeError` exceptions in `sa.engine.URL.cr…
nsoranzo Mar 22, 2021
c02fed4
Fix wrong `dialect_name` check
BradenM Mar 30, 2021
c76256c
Remove `u` unnecessary on Python 3
nsoranzo Mar 31, 2021
99c1324
Drop unnecessary `alias()` call
nsoranzo Apr 9, 2021
7e2a03a
fix get_columns tests
kvesteri Apr 7, 2021
c1dda36
fix instant defaults listener
kvesteri Apr 8, 2021
460e1da
remove sort_query and get_query_entities
kvesteri Apr 9, 2021
3807a2c
Remove also `get_query_entity_by_alias()`
nsoranzo Apr 9, 2021
8587bcb
Fix linting errors
nsoranzo Apr 9, 2021
a51367b
fix scalar_subquery warnings
kvesteri Apr 9, 2021
f62ce80
Update sqlalchemy_utils/compat.py
kvesteri Apr 9, 2021
f0020cf
fix selectable columns warning
kvesteri Apr 9, 2021
2a3de7b
Add health checks for SQL Server docker service
nsoranzo Apr 9, 2021
2b95760
Fix install_mssql.sh commands
nsoranzo Apr 9, 2021
8d576ee
Use `isolation_level` argument also for `mssql`
nsoranzo Apr 9, 2021
2683f8a
Restore `engine.dispose()`
nsoranzo Apr 9, 2021
c57f6dd
Add `coverage.xml` to `.gitignore`
nsoranzo Apr 9, 2021
f46a7a8
change tests to use non-deprecated class
kvesteri Apr 11, 2021
0b28d00
use scalar subquery for sqlalchemy 1.4
kvesteri Apr 11, 2021
823b1dc
use create_mock_engine for SA 1.4
kvesteri Apr 11, 2021
12d88d7
isort linting fixes
nsoranzo Apr 11, 2021
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
9 changes: 9 additions & 0 deletions .ci/install_mssql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

if [ ! -f /etc/apt/sources.list.d/microsoft-prod.list ]; then
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -r -s)/prod.list > /etc/apt/sources.list.d/mssql-release.list
fi

sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17 unixodbc
18 changes: 18 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Python linting
on: [push, pull_request]
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.6', '3.9']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: pip install tox
- name: Run linting
run: tox -e lint
62 changes: 62 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
tox_env: ['sqlalchemy14']
include:
- python-version: '3.6'
tox_env: 'sqlalchemy13'
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: sqlalchemy_utils_test
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
mysql:
image: mysql:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: sqlalchemy_utils_test
ports:
- 3306:3306
mssql:
image: mcr.microsoft.com/mssql/server:2017-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: Strong!Passw0rd
ports:
- 1433:1433
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install MS SQL stuff
run: bash .ci/install_mssql.sh
- name: Add hstore extension to the sqlalchemy_utils_test database
env:
PGHOST: localhost
PGPASSWORD: postgres
PGPORT: 5432
run: psql -U postgres -d sqlalchemy_utils_test -c 'CREATE EXTENSION hstore;'
- name: Install tox
run: pip install tox
- name: Run tests
env:
SQLALCHEMY_UTILS_TEST_POSTGRESQL_PASSWORD: postgres
run: tox -e ${{matrix.tox_env }}
1 change: 0 additions & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ known_first_party=sqlalchemy_utils
known_third_party=flexmock
line_length=79
multi_line_output=3
not_skip=__init__.py
order_by_type=false
40 changes: 0 additions & 40 deletions .travis.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .travis/install_mssql.sh

This file was deleted.

18 changes: 14 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm.session import close_all_sessions

from sqlalchemy_utils import (
aggregates,
coercion_listener,
i18n,
InstrumentedList
)

from sqlalchemy_utils.functions.orm import _get_class_registry
from sqlalchemy_utils.types.pg_composite import remove_composite_listeners


Expand Down Expand Up @@ -48,14 +49,23 @@ def postgresql_db_user():
return os.environ.get('SQLALCHEMY_UTILS_TEST_POSTGRESQL_USER', 'postgres')


@pytest.fixture(scope='session')
def postgresql_db_password():
return os.environ.get('SQLALCHEMY_UTILS_TEST_POSTGRESQL_PASSWORD', '')


@pytest.fixture(scope='session')
def mysql_db_user():
return os.environ.get('SQLALCHEMY_UTILS_TEST_MYSQL_USER', 'root')


@pytest.fixture
def postgresql_dsn(postgresql_db_user, db_name):
return 'postgresql://{0}@localhost/{1}'.format(postgresql_db_user, db_name)
def postgresql_dsn(postgresql_db_user, postgresql_db_password, db_name):
return 'postgresql://{0}:{1}@localhost/{2}'.format(
postgresql_db_user,
postgresql_db_password,
db_name
)


@pytest.fixture
Expand Down Expand Up @@ -166,7 +176,7 @@ def articles_count(self):

@articles_count.expression
def articles_count(cls):
Article = Base._decl_class_registry['Article']
Article = _get_class_registry(Base)['Article']
return (
sa.select([sa.func.count(Article.id)])
.where(Article.category_id == cls.id)
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
[bdist_wheel]
universal = 1

[flake8]
exclude =
.eggs
.git
.tox
.venv
build
docs/conf.py
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

Various utility functions and custom data types for SQLAlchemy.
"""
from setuptools import setup, find_packages
import os
import re
import sys

from setuptools import find_packages, setup

HERE = os.path.dirname(os.path.abspath(__file__))
PY3 = sys.version_info[0] == 3
Expand Down Expand Up @@ -58,9 +58,9 @@ def get_version():

# Add all optional dependencies to testing requirements.
test_all = []
for name, requirements in sorted(extras_require.items()):
for requirements in extras_require.values():
test_all += requirements
extras_require['test_all'] = test_all
extras_require['test_all'] = sorted(test_all)


setup(
Expand Down
2 changes: 0 additions & 2 deletions sqlalchemy_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
get_hybrid_properties,
get_mapper,
get_primary_keys,
get_query_entities,
get_referencing_foreign_keys,
get_tables,
get_type,
Expand All @@ -42,7 +41,6 @@
naturally_equivalent,
render_expression,
render_statement,
sort_query,
table_name
)
from .generic import generic_relationship # noqa
Expand Down
3 changes: 2 additions & 1 deletion sqlalchemy_utils/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class Rating(Base):
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.sql.functions import _FunctionGenerator

from .compat import get_scalar_subquery
from .functions.orm import get_column_key
from .relationships import (
chained_join,
Expand Down Expand Up @@ -452,7 +453,7 @@ def aggregate_query(self):
self.relationships[0].mapper.class_
)

return query.as_scalar()
return get_scalar_subquery(query)

def update_query(self, objects):
table = self.class_.__table__
Expand Down
5 changes: 5 additions & 0 deletions sqlalchemy_utils/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def get_scalar_subquery(query):
try:
return query.scalar_subquery()
except AttributeError:
nsoranzo marked this conversation as resolved.
Show resolved Hide resolved
return query.as_scalar()
7 changes: 1 addition & 6 deletions sqlalchemy_utils/functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
get_hybrid_properties,
get_mapper,
get_primary_keys,
get_query_entities,
get_tables,
get_type,
getdotattr,
Expand All @@ -40,8 +39,4 @@
table_name
)
from .render import render_expression, render_statement # noqa
from .sort_query import ( # noqa
make_order_by_deterministic,
QuerySorterException,
sort_query
)
from .sort_query import make_order_by_deterministic # noqa
Loading