diff options
author | Jason Kirtland <jek@discorporate.us> | 2008-09-27 18:11:40 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2008-09-27 18:11:40 +0000 |
commit | 8e5312975b9f05ef1b196880d116fb10b916e87e (patch) | |
tree | 68fd1ea2134ca80aae9a0410fa07d1ae02a6ef8e /lib/sqlalchemy | |
parent | 0d9fc31fa1a82f6707a11e4d854cc5fe60a6dd07 (diff) | |
download | sqlalchemy-8e5312975b9f05ef1b196880d116fb10b916e87e.tar.gz |
- Fixed shared state bug interfering with ScopedSession.mapper's
ability to apply default __init__ implementations on object
subclasses.
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/orm/scoping.py | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/lib/sqlalchemy/orm/scoping.py b/lib/sqlalchemy/orm/scoping.py index 5dd17a289..b557e0232 100644 --- a/lib/sqlalchemy/orm/scoping.py +++ b/lib/sqlalchemy/orm/scoping.py @@ -142,7 +142,7 @@ class _ScopedExt(MapperExtension): self.context = context self.validate = validate self.save_on_init = save_on_init - self.set_kwargs_on_init = None + self.set_kwargs_on_init = True def validating(self): return _ScopedExt(self.context, validate=True) @@ -162,26 +162,23 @@ class _ScopedExt(MapperExtension): if not 'query' in class_.__dict__: class_.query = query() - if self.set_kwargs_on_init is None: - self.set_kwargs_on_init = class_.__init__ is object.__init__ - if self.set_kwargs_on_init: - def __init__(self, **kwargs): - pass - class_.__init__ = __init__ + if self.set_kwargs_on_init and class_.__init__ is object.__init__: + class_.__init__ = self._default__init__(mapper) - def init_instance(self, mapper, class_, oldinit, instance, args, kwargs): - if self.save_on_init: - session = kwargs.pop('_sa_session', None) - - if self.set_kwargs_on_init: + def _default__init__(ext, mapper): + def __init__(self, **kwargs): for key, value in kwargs.items(): - if self.validate: + if ext.validate: if not mapper.get_property(key, resolve_synonyms=False, raiseerr=False): raise sa_exc.ArgumentError( "Invalid __init__ argument: '%s'" % key) - setattr(instance, key, value) - kwargs.clear() + setattr(self, key, value) + return __init__ + + def init_instance(self, mapper, class_, oldinit, instance, args, kwargs): + if self.save_on_init: + session = kwargs.pop('_sa_session', None) if self.save_on_init: session = session or self.context.registry() |