diff --git a/flask_sqlalchemy/__init__.py b/flask_sqlalchemy/__init__.py index 59b470a4..b1a81703 100644 --- a/flask_sqlalchemy/__init__.py +++ b/flask_sqlalchemy/__init__.py @@ -155,7 +155,14 @@ def __init__(self, db, autocommit=False, autoflush=True, **options): def get_bind(self, mapper=None, clause=None): # mapper is None if someone tries to just get a connection if mapper is not None: - info = getattr(mapper.mapped_table, 'info', {}) + try: + # SA >= 1.3 + persist_selectable = mapper.persist_selectable + except AttributeError: + # SA < 1.3 + persist_selectable = mapper.mapped_table + + info = getattr(persist_selectable, 'info', {}) bind_key = info.get('bind_key') if bind_key is not None: state = get_state(self.app) diff --git a/tests/test_basic_app.py b/tests/test_basic_app.py index 2cbd8029..aae00cb6 100644 --- a/tests/test_basic_app.py +++ b/tests/test_basic_app.py @@ -49,3 +49,13 @@ def test_query_recording(app, db, Todo): def test_helper_api(db): assert db.metadata == db.Model.metadata + + +def test_persist_selectable(app, db, Todo, recwarn): + """ In SA 1.3, mapper.mapped_table should be replaced with mapper.persist_selectable """ + with app.test_request_context(): + todo = Todo('Test 1', 'test') + db.session.add(todo) + db.session.commit() + + assert len(recwarn) == 0