From: Mike Bayer Date: Mon, 9 Mar 2015 19:24:37 +0000 (-0400) Subject: - fix a potential race condition where the per-mapper LRUCache used by X-Git-Tag: rel_1_0_0b1~31 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b8a39b8636c8abef350e17ecca61e2a215931c9b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - fix a potential race condition where the per-mapper LRUCache used by persistence.py could theoretically hit the limit of the cache (100 items by default) and at some points fail to have a key that we check for, due to the cleanup. This has never been observed so its likely that so far, the total number of INSERT, UPDATE and DELETE statement structures in real apps has not exceeded 100 on a per-mapper basis; this could happen for apps that run a very wide variety of attribute modified combinations into the unit of work, *and* which have very high concurrency going on. This change will be a lot more significant when we open up use of LRUCache + compiled cache with the baked query extension. --- diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 305fa4620f..067d32538a 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -991,9 +991,8 @@ class Connection(Connectable): dialect = self.dialect if 'compiled_cache' in self._execution_options: key = dialect, elem, tuple(sorted(keys)), len(distilled_params) > 1 - if key in self._execution_options['compiled_cache']: - compiled_sql = self._execution_options['compiled_cache'][key] - else: + compiled_sql = self._execution_options['compiled_cache'].get(key) + if compiled_sql is None: compiled_sql = elem.compile( dialect=dialect, column_keys=keys, inline=len(distilled_params) > 1)