From 7760e70d8d68355b5c0f13cce011f2c5da7b0823 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 21 Sep 2009 00:47:35 +0000 Subject: [PATCH] place the constructor level configuration within the COMPILE_MUTEX, to prevent half-constructed mappers from getting sucked into the compile() phase --- lib/sqlalchemy/orm/mapper.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) 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(). -- 2.47.3