Skip to content

Commit a66ee64

Browse files
authored
Merge pull request #753 from kurtmckee/rm-sqlalchemy-1.3-support
Drop support for sqlalchemy 1.3
2 parents ec84969 + 19a3295 commit a66ee64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+77
-267
lines changed

.github/workflows/test.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ jobs:
1313
- '3.12'
1414
tox_env: ['sqlalchemy14', 'sqlalchemy2']
1515
include:
16-
# Test against Python 3.9 and sqlalchemy 1.3
17-
- os: 'ubuntu-20.04'
18-
python-version: '3.9'
19-
tox_env: 'sqlalchemy13'
2016
# Test against Python 3.9 and sqlalchemy 1.4
2117
- os: 'ubuntu-20.04'
2218
python-version: '3.9'

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Unreleased changes
77
^^^^^^^^^^^^^^^^^^
88

99
- Drop support for Python 3.7 and 3.8.
10+
- Drop support for sqlalchemy 1.3.
1011
- Add support for Python 3.12.
1112
- Add a Read the Docs configuration file.
1213
- Make documentation builds reproducible.

conftest.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sqlalchemy.exc
88
from sqlalchemy import create_engine
99
from sqlalchemy.ext.hybrid import hybrid_property
10-
from sqlalchemy.orm import sessionmaker
10+
from sqlalchemy.orm import declarative_base, sessionmaker, synonym_for
1111
from sqlalchemy.orm.session import close_all_sessions
1212

1313
from sqlalchemy_utils import (
@@ -16,11 +16,6 @@
1616
i18n,
1717
InstrumentedList
1818
)
19-
from sqlalchemy_utils.compat import (
20-
_declarative_base,
21-
_select_args,
22-
_synonym_for
23-
)
2419
from sqlalchemy_utils.functions.orm import _get_class_registry
2520
from sqlalchemy_utils.types.pg_composite import remove_composite_listeners
2621

@@ -154,7 +149,7 @@ def connection(engine):
154149

155150
@pytest.fixture
156151
def Base():
157-
return _declarative_base()
152+
return declarative_base()
158153

159154

160155
@pytest.fixture
@@ -191,7 +186,7 @@ def articles_count(self):
191186
def articles_count(cls):
192187
Article = _get_class_registry(Base)['Article']
193188
return (
194-
sa.select(*_select_args(sa.func.count(Article.id)))
189+
sa.select(sa.func.count(Article.id))
195190
.where(Article.category_id == cls.id)
196191
.correlate(Article.__table__)
197192
.label('article_count')
@@ -201,7 +196,7 @@ def articles_count(cls):
201196
def name_alias(self):
202197
return self.name
203198

204-
@_synonym_for('name')
199+
@synonym_for('name')
205200
@property
206201
def name_synonym(self):
207202
return self.name
@@ -238,12 +233,7 @@ def session(request, engine, connection, Base, init_models):
238233
with connection.begin():
239234
Base.metadata.create_all(connection)
240235
Session = sessionmaker(bind=connection)
241-
try:
242-
# Enable sqlalchemy 2.0 behavior.
243-
session = Session(future=True)
244-
except TypeError:
245-
# sqlalchemy 1.3
246-
session = Session()
236+
session = Session(future=True)
247237
i18n.get_locale = get_locale
248238

249239
def teardown():

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get_version():
7575
include_package_data=True,
7676
platforms='any',
7777
install_requires=[
78-
'SQLAlchemy>=1.3',
78+
'SQLAlchemy>=1.4',
7979
],
8080
extras_require=extras_require,
8181
python_requires='>=3.9',

sqlalchemy_utils/aggregates.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ class Rating(Base):
371371
from sqlalchemy.ext.declarative import declared_attr
372372
from sqlalchemy.sql.functions import _FunctionGenerator
373373

374-
from .compat import _select_args, get_scalar_subquery
375374
from .functions.orm import get_column_key
376375
from .relationships import (
377376
chained_join,
@@ -455,7 +454,7 @@ def aggregate_query(self):
455454
self.relationships[0].mapper.class_
456455
)
457456

458-
return get_scalar_subquery(query)
457+
return query.scalar_subquery()
459458

460459
def update_query(self, objects):
461460
table = self.class_.__table__
@@ -490,7 +489,7 @@ def update_query(self, objects):
490489
return query.where(
491490
local.in_(
492491
sa.select(
493-
*_select_args(remote)
492+
remote
494493
).select_from(
495494
chained_join(*reversed(self.relationships))
496495
).where(

sqlalchemy_utils/compat.py

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,3 @@ def get_sqlalchemy_version(version=metadata("sqlalchemy")["Version"]):
1010
return tuple(int(v) for v in match.groups() if v is not None)
1111
except AttributeError:
1212
return ()
13-
14-
15-
_sqlalchemy_version = get_sqlalchemy_version()
16-
17-
18-
# In sqlalchemy 2.0, some functions moved to sqlalchemy.orm.
19-
# In sqlalchemy 1.3, they are only available in .ext.declarative.
20-
# In sqlalchemy 1.4, they are available in both places.
21-
#
22-
# WARNING
23-
# -------
24-
#
25-
# These imports are for internal, private compatibility.
26-
# They are not supported and may change or move at any time.
27-
# Do not import these in your own code.
28-
#
29-
30-
if _sqlalchemy_version >= (1, 4):
31-
from sqlalchemy.orm import declarative_base as _declarative_base
32-
from sqlalchemy.orm import synonym_for as _synonym_for
33-
else:
34-
from sqlalchemy.ext.declarative import \
35-
declarative_base as _declarative_base
36-
from sqlalchemy.ext.declarative import synonym_for as _synonym_for
37-
38-
39-
# scalar subqueries
40-
if _sqlalchemy_version >= (1, 4):
41-
def get_scalar_subquery(query):
42-
return query.scalar_subquery()
43-
else:
44-
def get_scalar_subquery(query):
45-
return query.as_scalar()
46-
47-
48-
# In sqlalchemy 2.0, select() columns are positional.
49-
# In sqlalchemy 1.3, select() columns must be wrapped in a list.
50-
#
51-
# _select_args() is designed so its return value can be unpacked:
52-
#
53-
# select(*_select_args(1, 2))
54-
#
55-
# When sqlalchemy 1.3 support is dropped, remove the call to _select_args()
56-
# and keep the arguments the same:
57-
#
58-
# select(1, 2)
59-
#
60-
# WARNING
61-
# -------
62-
#
63-
# _select_args() is a private, internal function.
64-
# It is not supported and may change or move at any time.
65-
# Do not import this in your own code.
66-
#
67-
if _sqlalchemy_version >= (1, 4):
68-
def _select_args(*args):
69-
return args
70-
else:
71-
def _select_args(*args):
72-
return [args]
73-
74-
75-
__all__ = (
76-
"_declarative_base",
77-
"get_scalar_subquery",
78-
"get_sqlalchemy_version",
79-
"_select_args",
80-
"_synonym_for",
81-
)

sqlalchemy_utils/generic.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ def get(self, state, dict_, passive=attributes.PASSIVE_OFF):
5353

5454
id = self.get_state_id(state)
5555

56-
try:
57-
target = session.get(target_class, id)
58-
except AttributeError:
59-
# sqlalchemy 1.3
60-
target = session.query(target_class).get(id)
56+
target = session.get(target_class, id)
6157

6258
# Return found (or not found) target.
6359
return target

sqlalchemy_utils/listeners.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ def auto_delete_orphans(attr):
143143
from sqlalchemy.ext.associationproxy import association_proxy
144144
from sqlalchemy import *
145145
from sqlalchemy.orm import *
146-
# Necessary in sqlalchemy 1.3:
147-
# from sqlalchemy.ext.declarative import declarative_base
148146
from sqlalchemy import event
149147
150148

sqlalchemy_utils/relationships/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import sqlalchemy.orm
33
from sqlalchemy.sql.util import ClauseAdapter
44

5-
from ..compat import _select_args
65
from .chained_join import chained_join # noqa
76

87

@@ -96,7 +95,7 @@ def select_correlated_expression(
9695
):
9796
relationships = list(reversed(path_to_relationships(path, root_model)))
9897

99-
query = sa.select(*_select_args(expr))
98+
query = sa.select(expr)
10099

101100
join_expr, aliases = chained_inverse_join(relationships, leaf_model)
102101

sqlalchemy_utils/types/encrypted/encrypted_type.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,7 @@ class StringEncryptedType(TypeDecorator, ScalarCoercible):
257257
258258
import sqlalchemy as sa
259259
from sqlalchemy import create_engine
260-
try:
261-
from sqlalchemy.orm import declarative_base
262-
except ImportError:
263-
# sqlalchemy 1.3
264-
from sqlalchemy.ext.declarative import declarative_base
260+
from sqlalchemy.orm import declarative_base
265261
from sqlalchemy.orm import sessionmaker
266262
267263
from sqlalchemy_utils import StringEncryptedType

0 commit comments

Comments
 (0)