Skip to content

Commit dcb9604

Browse files
committed
Moved a helper into a method so it can be overwriten.
1 parent c052145 commit dcb9604

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

flaskext/sqlalchemy.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@
4444
before_models_committed = _signals.signal('before-models-committed')
4545

4646

47-
def _create_scoped_session(db, options):
48-
if options is None:
49-
options = {}
50-
return orm.scoped_session(partial(_SignallingSession, db, **options))
51-
52-
5347
def _make_table(db):
5448
def _make_table(*args, **kwargs):
5549
if len(args) > 1 and isinstance(args[1], db.Column):
@@ -548,8 +542,7 @@ def __init__(self, app=None, use_native_unicode=True,
548542
self.use_native_unicode = use_native_unicode
549543
self.session_extensions = to_list(session_extensions, []) + \
550544
[_SignallingSessionExtension()]
551-
552-
self.session = _create_scoped_session(self, session_options)
545+
self.session = self.create_scoped_session(session_options)
553546

554547
self.Model = self.make_declarative_base()
555548
self.Model.query = _QueryProperty(self)
@@ -569,6 +562,12 @@ def metadata(self):
569562
"""Returns the metadata"""
570563
return self.Model.metadata
571564

565+
def create_scoped_session(self, options=None):
566+
"""Helper factory method that creates a scoped session."""
567+
if options is None:
568+
options = {}
569+
return orm.scoped_session(partial(_SignallingSession, self, **options))
570+
572571
def make_declarative_base(self):
573572
"""Creates the declarative base."""
574573
return declarative_base(cls=Model, name='Model',

0 commit comments

Comments
 (0)