Release 1.164.0 - #3905
Merged
Merged
Release 1.164.0#3905
Conversation
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
OpenAPI ChangesShow/hide changesUnexpected changes? Ensure your branch is up-to-date with |
Comment on lines
+2043
to
+2046
| mailgun_log_response["timestamp"] = datetime.fromisoformat( | ||
| mailgun_log_response["@timestamp"] | ||
| ).timestamp() | ||
| return mailgun_log_response |
Contributor
There was a problem hiding this comment.
Bug: The code directly accesses the "@timestamp" key from an external API response without error handling, which will cause a KeyError if the key is missing.
Severity: MEDIUM
Suggested Fix
Add defensive error handling when accessing the "@timestamp" key. Use the .get() method to provide a default or check for the key's existence before access. Alternatively, wrap the access in a try...except KeyError block to gracefully handle cases where the key is not in the response, preventing the admin action from crashing.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: b2b/api.py#L2043-L2046
Potential issue: The function `_unpack_event_data_from_api_response` directly accesses
the `@timestamp` key from a Mailgun API response using bracket notation
(`mailgun_log_response["@timestamp"]`). This assumes the key will always be present. If
the external Mailgun API returns a response where an item is missing the `@timestamp`
key for any reason (e.g., API change, malformed data, or version mismatch), this will
raise an unhandled `KeyError`. This exception would crash the newly introduced
`backfill_email_events` admin action. The code path that parses the API response is not
covered by any tests, increasing the risk.
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Zaman Afzal
Chris Chudzicki
annagav
Dan Subak
Ahtisham Shahid