Skip to content

Commit a1cd528

Browse files
authored
Merge pull request #139 from TTWShell/upgrade/flask-sqlalchemy
Upgrade/flask sqlalchemy
2 parents 0fb2f88 + 00d41f7 commit a1cd528

21 files changed

+991
-843
lines changed

.circleci/config.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ jobs:
3131
tox -- --cov-report=xml
3232
codecov
3333
34-
test-py36:
34+
test-py310:
3535
docker:
36-
- image: circleci/python:3.6.13
36+
- image: circleci/python:3.10.0
3737
user: root
3838
working_directory: ~/repo
3939
steps:
@@ -44,7 +44,6 @@ jobs:
4444
pip install flake8 pytest pytest-cov pytest-env
4545
pip install --editable ".[hobbit,hobbit_core]"
4646
pip install celery
47-
pip install "MarkupSafe==2.0.1" blinker[flask]
4847
- run:
4948
name: use flake8 check self
5049
command: flake8 .
@@ -77,7 +76,6 @@ jobs:
7776
pip install flake8 pytest pytest-cov pytest-env
7877
pip install --editable ".[hobbit,hobbit_core]"
7978
pip install celery
80-
pip install "MarkupSafe==2.0.1" blinker[flask]
8179
- run:
8280
name: use flake8 check self
8381
command: flake8 .
@@ -113,7 +111,7 @@ workflows:
113111
test:
114112
jobs:
115113
- tox
116-
- test-py36:
114+
- test-py310:
117115
requires:
118116
- tox
119117
- test-py37:

Pipfile.lock

Lines changed: 835 additions & 691 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hobbit/static/bootstrap/rivendell/tests/__init__.py.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BaseTest:
2727
exclude_tables = []
2828
models = {
2929
m.__tablename__: m
30-
for m in db.Model._decl_class_registry.values()
30+
for m in db.Model.registry._class_registry.values()
3131
if isinstance(m, model.DefaultMeta)
3232
}
3333
tables = db.metadata.sorted_tables

hobbit/static/bootstrap/rivendell/tests/test_tools.py.jinja2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ class TestAPIExample(BaseTest):
55

66
def test_ping_api(self, client):
77
resp = client.get('/api/ping')
8-
assert resp.status_code == 200
8+
assert resp.status == 200
99

1010

1111
class TestOption(BaseTest):
1212

1313
def test_options(self, client):
1414
resp = client.get('/api/options')
15-
assert resp.status_code == 200
15+
assert resp.status == 200
1616

hobbit/static/bootstrap/shire/tests/__init__.py.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BaseTest:
2727
exclude_tables = []
2828
models = {
2929
m.__tablename__: m
30-
for m in db.Model._decl_class_registry.values()
30+
for m in db.Model.registry._class_registry.values()
3131
if isinstance(m, model.DefaultMeta)
3232
}
3333
tables = db.metadata.sorted_tables

hobbit/static/bootstrap/shire/tests/test_tools.py.jinja2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ class TestAPIExample(BaseTest):
55

66
def test_ping_api(self, client):
77
resp = client.get('/api/ping')
8-
assert resp.status_code == 200
8+
assert resp.status == 200
99

1010

1111
class TestOption(BaseTest):
1212

1313
def test_options(self, client):
1414
resp = client.get('/api/options')
15-
assert resp.status_code == 200
15+
assert resp.status == 200
1616

hobbit_core/db.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515

1616
class _BaseModel:
1717

18-
__mapper_args__ = {
19-
'order_by': 'id',
20-
}
21-
2218
def __repr__(self) -> str:
2319
"""You can set label property.
2420
@@ -74,7 +70,7 @@ def __new__(cls, name, bases, attrs):
7470
DateTime, index=True, nullable=False, server_default=func.now(),
7571
onupdate=func.now())
7672

77-
if db.get_engine(bind=attrs.get('__bind_key__')).name == 'oracle':
73+
if db.get_engine(bind_key=attrs.get('__bind_key__')).name == 'oracle':
7874
sequence_name = attrs.get('sequence_name') or \
7975
f'{name}_{primary_key_name}_seq'
8076
if current_app.config['HOBBIT_UPPER_SEQUENCE_NAME']:

hobbit_core/err_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def handler_werkzeug_exceptions(cls, e):
3535
status=e.code)
3636

3737
@classmethod
38-
def handler_sqlalchemy_orm_exc(cls, e):
38+
def handler_sqlalchemy_exc(cls, e):
3939
code, message, detail = 500, RESP_MSGS[500], repr(e)
4040

4141
if isinstance(e, orm_exc.NoResultFound):

hobbit_core/pagination.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def pagination(obj: 'model.DefaultMeta', page: int, page_size: int,
7979
order_exp.append(getattr(obj, column))
8080
qexp = qexp.order_by(*order_exp)
8181

82-
items = qexp.paginate(page, page_size, error_out=False)
82+
items = qexp.paginate(page=page, per_page=page_size, error_out=False)
83+
8384
return {
8485
'items': items.items, 'page': page, 'page_size': page_size,
8586
'total': items.total,

hobbit_core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def bulk_create_or_update_on_duplicate(
275275
if column in item and item[column] is None:
276276
item[column] = ''
277277

278-
engine = db.get_engine(bind=getattr(model_cls, '__bind_key__', None))
278+
engine = db.get_engine(bind_key=getattr(model_cls, '__bind_key__', None))
279279
if engine.name == 'postgresql':
280280
sql_on_update = ', '.join([
281281
f' {field} = excluded.{field}'

setup.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ def gen_data(data_root='static'):
2626
import pypandoc
2727
long_description = pypandoc.convert_file('README.md', 'rst')
2828
long_description_content_type = 'text/x-rst'
29-
except(OSError, ImportError):
29+
except (OSError, ImportError):
3030
long_description = open('README.md').read()
3131

3232

3333
setup(
3434
name='hobbit-core',
35-
version='2.2.3',
36-
python_requires='>=3.6, <4',
35+
version='3.0.0.rc1',
36+
python_requires='>=3.7, <4',
3737
description='Hobbit - A flask project generator.',
3838
long_description=long_description,
3939
long_description_content_type=long_description_content_type,
@@ -42,7 +42,6 @@ def gen_data(data_root='static'):
4242
url='https://github.com/TTWShell/hobbit-core',
4343
classifiers=[
4444
'Topic :: Utilities',
45-
'Programming Language :: Python :: 3.6',
4645
'Programming Language :: Python :: 3.7',
4746
'Programming Language :: Python :: 3.8',
4847
'Programming Language :: Python :: 3.9',
@@ -56,12 +55,12 @@ def gen_data(data_root='static'):
5655
install_requires=[],
5756
extras_require={
5857
'hobbit_core': [
59-
'Flask>=1.0.0,<2',
58+
'Flask>=2.0,<3',
6059
'flask-marshmallow>=0.14.0,<1',
6160
'Flask-Migrate>=3.0.1,<4',
6261
'flask-shell-ipython>=0.4.1',
63-
'SQLAlchemy>=1.3.0,< 1.4.0',
64-
'Flask-SQLAlchemy>=2.5.1,<3',
62+
'SQLAlchemy>=1.4.0,< 2',
63+
'Flask-SQLAlchemy>=3.0.0,<4',
6564
'marshmallow-enum>=1.5.1,<2',
6665
'marshmallow-sqlalchemy>=0.26.1,<3',
6766
'webargs>=8.0.0,<9',
@@ -71,8 +70,9 @@ def gen_data(data_root='static'):
7170
],
7271
'hobbit': [
7372
'Click>=6.7',
74-
'Jinja2>=2.10',
73+
'Jinja2>=3.0',
7574
'inflect>=2.1.0',
75+
'markupsafe>=2.0.1',
7676
],
7777
},
7878
entry_points={

tests/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ class BaseTest(object):
1313
@classmethod
1414
def setup_class(cls):
1515
with app.app_context():
16-
db.create_all(bind=None)
17-
db.create_all(bind='mysql')
16+
db.create_all(bind_key=None)
17+
db.create_all(bind_key='mysql')
1818

1919
@classmethod
2020
def teardown_class(cls):
2121
with app.app_context():
22-
db.drop_all(bind=None)
23-
db.drop_all(bind='mysql')
22+
db.drop_all(bind_key=None)
23+
db.drop_all(bind_key='mysql')
2424

2525
def teardown_method(self, method):
2626
with app.app_context():
27-
for m in [m for m in db.Model._decl_class_registry.values()
28-
# db.Model.registry._class_registry.values()
27+
for m in [m for m in db.Model.registry._class_registry.values()
2928
if isinstance(m, model.DefaultMeta) and
3029
getattr(m, '__bind_key__', None) != 'oracle']:
3130
db.session.query(m).delete()

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def assert_session(app):
2828
with app.app_context():
2929
conn = tdb.engine.connect()
3030
options = dict(bind=conn, binds={})
31-
sess = tdb.create_scoped_session(options=options)
31+
sess = tdb._make_scoped_session(options=options)
3232
assert sess.autocommit is False
3333
yield sess
3434
sess.remove()
@@ -47,7 +47,7 @@ def auto_session(app):
4747
with app.app_context():
4848
conn = tdb.engine.connect()
4949
options = dict(bind=conn, binds={}, autocommit=True)
50-
sess = tdb.create_scoped_session(options=options)
50+
sess = tdb._make_scoped_session(options=options)
5151
assert sess.autocommit is True
5252
yield sess
5353
sess.remove()

tests/test_app/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def signalling(app, changes, **kwargs):
2424
for instance, operation in changes:
2525
if instance.__tablename__ in [i.__tablename__ for i in [User]]:
2626
models_committed.disconnect(signalling)
27-
session = db.create_scoped_session()
27+
conn = db.engine.connect()
28+
options = dict(bind=conn, binds={})
29+
session = db._make_scoped_session(options=options)
2830
user = session.query(User).first()
2931
if user and user.username == 'signalling_test':
3032
user.username = 'signalling_ok'

0 commit comments

Comments
 (0)