]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
place the constructor level configuration within the COMPILE_MUTEX,
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 21 Sep 2009 00:47:35 +0000 (00:47 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 21 Sep 2009 00:47:35 +0000 (00:47 +0000)
to prevent half-constructed mappers from getting sucked into the compile()
phase

lib/sqlalchemy/orm/mapper.py

index 907fcd5c3ad6b84d943647cc6d6ba30ffb18b02d..7c4ec23f6faeab8b12c1dca3a71244b55b1e9c04 100644 (file)
@@ -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().