-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Email with custom notifications not working #14839
Conversation
59a23d5
to
4e10b43
Compare
awx/main/models/notifications.py
Outdated
msg = '' | ||
except (TemplateSyntaxError, UndefinedError, SecurityError) as e: | ||
msg = e # __str__ | ||
msg += '\n'.join(traceback.format_exception(None, e, e.__traceback__)) |
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.
This is not going to work in the way that you expect.
In [1]: try:
...: raise Exception("foo")
...: except Exception as e:
...: msg = e
...: msg += "bar"
...:
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
Input In [1], in <cell line: 1>()
1 try:
----> 2 raise Exception("foo")
3 except Exception as e:
Exception: foo
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
Input In [1], in <cell line: 1>()
3 except Exception as e:
4 msg = e
----> 5 msg += "bar"
TypeError: unsupported operand type(s) for +=: 'Exception' and 'str'
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.
Also, using +=
to build up strings is an anti-pattern in Python. I'd instead suggest something like
msg = '\n'.join([
str(e),
...whatever...
])
awx/main/models/notifications.py
Outdated
except (TemplateSyntaxError, UndefinedError, SecurityError): | ||
msg = '' | ||
except (TemplateSyntaxError, UndefinedError, SecurityError) as e: | ||
msg = e # __str__ |
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.
what does # __str__
do?
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.
Nothing.
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.
The concept seems good, but the exception handling is broken as-is.
e14b4a3
to
f390521
Compare
SUMMARY
This targets "Email with custom notifications not working"
related #13983
This checks for blank body and add templates errors for the user.
ISSUE TYPE
COMPONENT NAME