Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(2.x): session get bind signature #1001

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 2.5.2
-------------

Unreleased

- Fix session ``get_bind`` signature for SQLAlchemy 1.4. :issue:`953`


Version 2.5.1
-------------

Expand Down
14 changes: 12 additions & 2 deletions flask_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,12 @@ def __init__(self, db, autocommit=False, autoflush=True, **options):
bind=bind, binds=binds, **options
)

def get_bind(self, mapper=None, clause=None):
def get_bind(
self,
mapper=None,
*args,
**kwargs
):
"""Return the engine or connection for a given model or
table, using the ``__bind_key__`` if it is set.
"""
Expand All @@ -202,7 +207,12 @@ def get_bind(self, mapper=None, clause=None):
if bind_key is not None:
state = get_state(self.app)
return state.db.get_engine(self.app, bind=bind_key)
return SessionBase.get_bind(self, mapper, clause)
return SessionBase.get_bind(
self,
mapper,
*args,
**kwargs
)


class _SessionSignalEvents(object):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sqlalchemy as sa
from sqlalchemy.engine import Engine
from sqlalchemy.orm import sessionmaker

import flask_sqlalchemy as fsa
Expand Down Expand Up @@ -63,3 +64,8 @@ class QazWsx(db.Model):

def test_listen_to_session_event(db):
sa.event.listen(db.session, 'after_commit', lambda session: None)


def test_session_get_bind(app, db):
with app.test_request_context():
assert isinstance(db.session.get_bind(), Engine)