Merge "Address concurrent mutation of sqlalchemy backend"
This commit is contained in:
		| @@ -243,14 +243,15 @@ class SQLAlchemyBackend(base.Backend): | |||||||
|             self._engine = engine |             self._engine = engine | ||||||
|             self._owns_engine = False |             self._owns_engine = False | ||||||
|         else: |         else: | ||||||
|             self._engine = None |             self._engine = self._create_engine(self._conf) | ||||||
|             self._owns_engine = True |             self._owns_engine = True | ||||||
|         self._validated = False |         self._validated = False | ||||||
|  |  | ||||||
|     def _create_engine(self): |     @staticmethod | ||||||
|  |     def _create_engine(conf): | ||||||
|         # NOTE(harlowja): copy the internal one so that we don't modify it via |         # NOTE(harlowja): copy the internal one so that we don't modify it via | ||||||
|         # all the popping that will happen below. |         # all the popping that will happen below. | ||||||
|         conf = copy.deepcopy(self._conf) |         conf = copy.deepcopy(conf) | ||||||
|         engine_args = { |         engine_args = { | ||||||
|             'echo': _as_bool(conf.pop('echo', False)), |             'echo': _as_bool(conf.pop('echo', False)), | ||||||
|             'convert_unicode': _as_bool(conf.pop('convert_unicode', True)), |             'convert_unicode': _as_bool(conf.pop('convert_unicode', True)), | ||||||
| @@ -320,8 +321,6 @@ class SQLAlchemyBackend(base.Backend): | |||||||
|  |  | ||||||
|     @property |     @property | ||||||
|     def engine(self): |     def engine(self): | ||||||
|         if self._engine is None: |  | ||||||
|             self._engine = self._create_engine() |  | ||||||
|         return self._engine |         return self._engine | ||||||
|  |  | ||||||
|     def get_connection(self): |     def get_connection(self): | ||||||
| @@ -336,15 +335,11 @@ class SQLAlchemyBackend(base.Backend): | |||||||
|         return conn |         return conn | ||||||
|  |  | ||||||
|     def close(self): |     def close(self): | ||||||
|         if self._engine is not None and self._owns_engine: |         # NOTE(harlowja): Only dispose of the engine if we actually own the | ||||||
|             # NOTE(harlowja): Only dispose of the engine and clear it from |         # engine in the first place. If the user passed in their own engine | ||||||
|             # our local state if we actually own the engine in the first |         # we should not be disposing it on their behalf... | ||||||
|             # place. If the user passed in their own engine we should not |         if self._owns_engine: | ||||||
|             # be disposing it on their behalf (and we shouldn't be clearing |  | ||||||
|             # our local engine either, since then we would just recreate a |  | ||||||
|             # new engine if the engine property is accessed). |  | ||||||
|             self._engine.dispose() |             self._engine.dispose() | ||||||
|             self._engine = None |  | ||||||
|         self._validated = False |         self._validated = False | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jenkins
					Jenkins