summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/scoping.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-09-21 09:33:30 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-09-21 09:33:30 -0400
commit634d54742523883316bd7768c8d2918e8410aa62 (patch)
treef48d467bd122b610aaec339c89c69be070d050c2 /lib/sqlalchemy/orm/scoping.py
parent4fbd16e045cc0daed754f2c4f9732ba1ac128205 (diff)
downloadsqlalchemy-634d54742523883316bd7768c8d2918e8410aa62.tar.gz
- scoped_session emits a warning when configure() is
called if a Session is already present (checks only the current thread) [ticket:1924]
Diffstat (limited to 'lib/sqlalchemy/orm/scoping.py')
-rw-r--r--lib/sqlalchemy/orm/scoping.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/scoping.py b/lib/sqlalchemy/orm/scoping.py
index c1a5fd577..140328e24 100644
--- a/lib/sqlalchemy/orm/scoping.py
+++ b/lib/sqlalchemy/orm/scoping.py
@@ -6,7 +6,8 @@
import sqlalchemy.exceptions as sa_exc
from sqlalchemy.util import ScopedRegistry, ThreadLocalRegistry, \
- to_list, get_cls_kwargs, deprecated
+ to_list, get_cls_kwargs, deprecated,\
+ warn
from sqlalchemy.orm import (
EXT_CONTINUE, MapperExtension, class_mapper, object_session
)
@@ -45,7 +46,8 @@ class ScopedSession(object):
scope = kwargs.pop('scope', False)
if scope is not None:
if self.registry.has():
- raise sa_exc.InvalidRequestError("Scoped session is already present; no new arguments may be specified.")
+ raise sa_exc.InvalidRequestError("Scoped session is already present; "
+ "no new arguments may be specified.")
else:
sess = self.session_factory(**kwargs)
self.registry.set(sess)
@@ -85,6 +87,11 @@ class ScopedSession(object):
def configure(self, **kwargs):
"""reconfigure the sessionmaker used by this ScopedSession."""
+
+ if self.registry.has():
+ warn('At least one scoped session is already present. '
+ ' configure() can not affect sessions that have '
+ 'already been created.')
self.session_factory.configure(**kwargs)