-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(serialization): Gracefully handle None results during serialization #105418
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
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| with sentry_sdk.start_span(op="serialize.iterate", name=type(serializer).__name__): | ||
| return [serializer(o, attrs=attrs.get(o, {}), user=user, **kwargs) for o in objects] | ||
| return [ |
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.
Index out of bounds when serializing single object fails
When serialize() is called with a single object, it wraps it in a list, recursively calls itself, and then accesses [0] on the result. With the new filtering logic that removes None results, if that single object's serialization fails and returns None, the returned list will be empty, causing an IndexError at line 55.
Additional Locations (1)
| if u is None: | ||
| continue | ||
| # Filter out the emails from the user data | ||
| u.pop("emails", None) |
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.
Bug: Filtering None values in Serializer.serialize_many() can cause an IndexError in downstream code that accesses list elements by index, such as in dashboard.py.
Severity: HIGH | Confidence: High
🔍 Detailed Analysis
The change in Serializer.serialize_many() filters out None values from its results. Previously, if a user serialization failed, the list would contain a None element. Now, the list will be empty in that scenario. Downstream code in dashboard.py directly accesses the first element of the returned list using [0]. When the new change causes an empty list to be returned, this direct access will raise an IndexError: list index out of range, causing a crash when a dashboard operation requests a user that fails to serialize.
💡 Suggested Fix
Instead of filtering out None values, which changes the length of the returned list, consider propagating them. Alternatively, update all call sites that rely on list indexing, like the one in dashboard.py, to handle cases where the list might be empty. For example, check the list's length before accessing an index.
🤖 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: src/sentry/api/serializers/models/organization_member/base.py#L48-L51
Potential issue: The change in `Serializer.serialize_many()` filters out `None` values
from its results. Previously, if a user serialization failed, the list would contain a
`None` element. Now, the list will be empty in that scenario. Downstream code in
`dashboard.py` directly accesses the first element of the returned list using `[0]`.
When the new change causes an empty list to be returned, this direct access will raise
an `IndexError: list index out of range`, causing a crash when a dashboard operation
requests a user that fails to serialize.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7873747
❌ 3 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
|
We should probably figure out the root cause i.e. why serialization is failing |
Fixes JAVASCRIPT-35TZ. The issue was that: User serialization failure returns null, which OrganizationMemberSerializer fails to handle, propagating null members to frontend.
Nonevalues resulting from serialization failures are skipped inOrganizationMemberSerializer.Serializer.serialize_manyto use the walrus operator to assign the serialization result and filter out anyNoneresults before returning the list.This fix was generated by Seer in Sentry, triggered by Ryan Albrecht. 👁️ Run ID: 7873449
Not quite right? Click here to continue debugging with Seer.
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.