summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2023-03-09 13:54:07 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2023-03-10 15:07:27 -0500
commit2c9796b10c3e85450afdeedc4003607abda2f2db (patch)
tree916866e37253c920acbf6d61adafbc64c2cb159b /lib/sqlalchemy/sql
parent9c0715181de6f03543c7ac9038c481f57f773d49 (diff)
downloadsqlalchemy-2c9796b10c3e85450afdeedc4003607abda2f2db.tar.gz
repair broken lambda patch
in I4e0b627bfa187f1780dc68ec81b94db1c78f846a the 1.4 version has more changes than the main version, which failed to get the entire change, yet the whole thing was merged. Restore the missing mutex related code to the main version. Fixed regression where the fix for :ticket:`8098`, which was released in the 1.4 series and provided a layer of concurrency-safe checks for the lambda SQL API, included additional fixes in the patch that failed to be applied to the main branch. These additional fixes have been applied. Change-Id: Id172e09c421dafa6ef1d40b383aa4371de343864 References: #8098 Fixes: #9461
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/lambdas.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/sqlalchemy/sql/lambdas.py b/lib/sqlalchemy/sql/lambdas.py
index 04bf86ee6..12175c75d 100644
--- a/lib/sqlalchemy/sql/lambdas.py
+++ b/lib/sqlalchemy/sql/lambdas.py
@@ -272,11 +272,16 @@ class LambdaElement(elements.ClauseElement):
if rec is None:
if cache_key is not _cache_key.NO_CACHE:
- rec = AnalyzedFunction(
- tracker, self, apply_propagate_attrs, fn
- )
- rec.closure_bindparams = bindparams
- lambda_cache[tracker_key + cache_key] = rec
+ with AnalyzedCode._generation_mutex:
+ key = tracker_key + cache_key
+ if key not in lambda_cache:
+ rec = AnalyzedFunction(
+ tracker, self, apply_propagate_attrs, fn
+ )
+ rec.closure_bindparams = bindparams
+ lambda_cache[key] = rec
+ else:
+ rec = lambda_cache[key]
else:
rec = NonAnalyzedFunction(self._invoke_user_fn(fn))