Skip to content

Commit

Permalink
Use persist_selectable for SA >= 1.3 to avoid warnings
Browse files Browse the repository at this point in the history
refs #679
refs #671
  • Loading branch information
rsyring committed Mar 9, 2019
1 parent 17e155f commit 2ddc775
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion flask_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_basic_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2ddc775

Please sign in to comment.