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}'

0 commit comments

Comments
 (0)