-
-
Notifications
You must be signed in to change notification settings - Fork 782
Rollback workflow DB change on errors field #4892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Rolls back part of #4854. |
|
It seems like we could have more escaping and unescaping tests in The other thing to consider is that the code in |
|
I can add my test case to st2common/tests/unit/test_mongoescape.py. But i'll keep my specific test for the workflow engine. The basic tests in test_mongoescape.py didn't catch the use case for the workflow engine and definitely didn't catch the bug in the unescape where it's translating twice but not passing the translated value from one _translate_chars to the second _translate_chars. Also, the second _translate_chars is actually redundant and adds performance overhead so I actually consolidate the two calls into one. |
|
The second call isn't redundant, it just very much looks like it is. The Still very weird and overdue for a refactoring like this. I believe this code is also an excellent candidate to be implemented with single dispatch: from functools import singledispatch
# ...
@singledispatch
def _translate_chars(field, translation):
return field
@_translate_chars.register(list)
def _translate_chars_in_list(field, translation):
return [_translate_chars(value, translation) for value in field]
def _translate_chars_in_key(key, translation):
for k, v in [(k, v) for k, v in six.iteritems(translation) if k in key]:
key = key.replace(k, v)
return key
@_translate_chars.register(dict)
def _translate_chars_in_dict:
return {
_translate_chars_in_key(k, translation): _translate_chars(v, translation)
for k, v in six.iteritems(field)
}
def escape_chars(field):
return _translate_chars(fast_deepcopy(field), ESCAPE_TRANSLATION)
def unescape_chars(field):
return _translate_chars(fast_deepcopy(field), UNESCAPE_TRANSLATION) |
nmaludy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about trying to improve performance. Also, probably good to benchmark and see what method wins.
5eb319d to
dbf78d4
Compare
|
As of commit |
nmaludy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Rollback workflow DB change on errors field because there are cases where action execution result is included in the detail of the error log and the action execution result can contain dictionary with key that has dot notation such as IP address. Also identified and fix mongoescape bug on handling list of dicts in dynamic field and also multiple iteration on unescape.
dbf78d4 to
d0e11f8
Compare
Rollback workflow DB change on errors field because there are cases where action execution result is included in the detail of the error log and the action execution result can contain dictionary with key that has dot notation such as IP address. Also identified and fix mongoescape bug on handling list of dicts in dynamic field and also multiple iteration on unescape.