Clone cached action definitions

* Once in a while we get DetachedInstanceError for action definitions
  and it happens when they are fetched from cache. We must always
  clone persistent objects before caching them.

Change-Id: I1d0cffea6775eb258dcefc0dbb8a6ee18effe597
Closes-Bug: #1803528
This commit is contained in:
Renat Akhmerov 2018-11-15 18:22:09 +07:00
parent 0d85973f52
commit 90ddf442ee
2 changed files with 13 additions and 6 deletions

View File

@ -69,17 +69,19 @@ def find_action_definition_by_name(action_name):
:return: Action definition (possibly a cached value). :return: Action definition (possibly a cached value).
""" """
with _ACTION_DEF_CACHE_LOCK: with _ACTION_DEF_CACHE_LOCK:
action_definition = _ACTION_DEF_CACHE.get(action_name) action_def = _ACTION_DEF_CACHE.get(action_name)
if action_definition: if action_def:
return action_definition return action_def
action_definition = db_api.load_action_definition(action_name) action_def = db_api.load_action_definition(action_name)
with _ACTION_DEF_CACHE_LOCK: with _ACTION_DEF_CACHE_LOCK:
_ACTION_DEF_CACHE[action_name] = action_definition _ACTION_DEF_CACHE[action_name] = (
action_def.get_clone() if action_def else None
)
return action_definition return action_def
def find_task_executions_by_name(wf_ex_id, task_name): def find_task_executions_by_name(wf_ex_id, task_name):

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Sometimes Mistral was raising DetachedInstanceError for action defintions
coming from cache. It's now fixed by cloning objects before caching them.