Skip to content

Commit

Permalink
Fix compatibility with older marshmallow-sqlalchemy versions (#190)
Browse files Browse the repository at this point in the history
close #189
  • Loading branch information
sloria committed Jun 7, 2020
1 parent c9db03c commit 63be1ae
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
Changelog
=========

(unreleased)
************
0.13.0 (unreleased)
*******************

Bug fixes:

* Fix compatibility with marshmallow-sqlalchemy<0.22.0 (:issue:`189`).
Thanks :user:`PatrickRic` for reporting.

Other changes:

* Remove unused ``flask_marshmallow.sqla.SchemaOpts``.

Expand Down
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
- py38-marshmallow2
- py38-marshmallow3

- py38-lowest
- py38-marshmallowdev

- docs
Expand Down
8 changes: 5 additions & 3 deletions src/flask_marshmallow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ def init_app(self, app):
"""
app.extensions = getattr(app, "extensions", {})

# If using Flask-SQLAlchemy, attach db.session to ModelSchema
# If using Flask-SQLAlchemy, attach db.session to SQLAlchemySchema
if has_sqla and "sqlalchemy" in app.extensions:
db = app.extensions["sqlalchemy"].db
self.SQLAlchemySchema.OPTIONS_CLASS.session = db.session
self.SQLAlchemyAutoSchema.OPTIONS_CLASS.session = db.session
if self.SQLAlchemySchema:
self.SQLAlchemySchema.OPTIONS_CLASS.session = db.session
if self.SQLAlchemyAutoSchema:
self.SQLAlchemyAutoSchema.OPTIONS_CLASS.session = db.session
app.extensions[EXTENSION_NAME] = self
4 changes: 4 additions & 0 deletions tests/test_sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def absolute_url(self):
yield Bunch(Author=AuthorModel, Book=BookModel)
db.drop_all()

def test_can_initialize_extensions(self, extapp):
assert "flask-marshmallow" in extapp.extensions
assert "sqlalchemy" in extapp.extensions

@requires_sqlalchemyschema
def test_can_declare_sqla_schemas(self, extma, models, db):
class AuthorSchema(extma.SQLAlchemySchema):
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ envlist=
lint
py{27,35,36,37,38}-marshmallow2
py{35,36,37,38}-marshmallow3
py37-marshmallowdev
py38-lowest
py38-marshmallowdev
docs

[testenv]
Expand All @@ -12,6 +13,8 @@ deps =
marshmallow2: marshmallow>=2.0.0,<3.0.0
marshmallow3: marshmallow>=3.0.0a1,<4.0.0
marshmallowdev: https://github.com/marshmallow-code/marshmallow/archive/dev.tar.gz
lowest: marshmallow>=2.0.0,<3.0.0
lowest: marshmallow-sqlalchemy==0.13.0
commands = pytest {posargs}

[testenv:lint]
Expand Down

0 comments on commit 63be1ae

Please sign in to comment.