From: Mike Bayer Date: Mon, 21 Sep 2009 00:47:35 +0000 (+0000) Subject: place the constructor level configuration within the COMPILE_MUTEX, X-Git-Tag: rel_0_6beta1~276 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7760e70d8d68355b5c0f13cce011f2c5da7b0823;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git place the constructor level configuration within the COMPILE_MUTEX, to prevent half-constructed mappers from getting sucked into the compile() phase --- diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 907fcd5c3a..7c4ec23f6f 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -192,16 +192,23 @@ class Mapper(object): self.exclude_properties = exclude_properties self.compiled = False - - self._configure_inheritance() - self._configure_extensions() - self._configure_class_instrumentation() - self._configure_properties() - self._configure_pks() - global _new_mappers - _new_mappers = True - self._log("constructed") - + + # prevent this mapper from being constructed + # while a compile() is occuring (and defer a compile() + # until construction succeeds) + _COMPILE_MUTEX.acquire() + try: + self._configure_inheritance() + self._configure_extensions() + self._configure_class_instrumentation() + self._configure_properties() + self._configure_pks() + global _new_mappers + _new_mappers = True + self._log("constructed") + finally: + _COMPILE_MUTEX.release() + # configurational / mutating methods. not threadsafe # except for compile().