-
Notifications
You must be signed in to change notification settings - Fork 4
Sync #12
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
Code Review by Qodo (Alpha)Automated review surfaced additional insights for this pull request.
Issue Findings 1. Quota Refund Logic Inverted □
|
| self.__get_redis_key(quota, timestamp, shift, project.organization_id) | ||
| ) | ||
| pipe.incr(return_key, quantity) | ||
| pipe.decr(return_key, quantity) |
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.
1. Quota Refund Logic Inverted □ 🐞 Bug
The refund method changed from pipe.incr(return_key, quantity) to pipe.decr(return_key, quantity). This inverts the refund logic. The refund key is meant to track how many events have been refunded, and this value is subtracted from the usage count (line 171: int(result.value or 0) - int(refund_result.value or 0)). By using decr instead of incr, the refund key becomes negative, which when subtracted from usage actually increases the reported usage instead of decreasing it. This breaks the quota refund mechanism entirely.
Agent Prompt
Copy this prompt and use it to remediate the issue with your preferred AI generation tools
## Issue Description
The quota refund logic has been inverted by changing from `incr` to `decr`. The refund key tracks the count of refunded events, which is subtracted from total usage. Using `decr` makes this value negative, causing refunds to increase usage instead of decrease it.
## Issue Context
When events are refunded (e.g., after being discarded due to rate limiting or errors), the system should decrease the quota usage. The refund key stores a positive count of refunded items, which is subtracted from the raw usage count in the `get_usage` method.
## Fix Focus Areas
- src/sentry/quotas/redis.py[228-228]
| reason = extra_context.get("reason", 0) | ||
| return { | ||
| "reason": GroupSubscriptionReason.descriptions.get(reason, "are subscribed to this issue") | ||
| "reason": GroupSubscriptionReason.descriptions.get(reason, "subscribed") |
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.
2.Incorrect Default for Notification Reason □ 🐞 Bug
The default value for the notification reason changed from "are subscribed to this issue" to "subscribed". Looking at the GroupSubscriptionReason.descriptions dictionary, all the description values are complete sentences starting with verbs (e.g., "have commented on this issue", "have been assigned to this issue"). The new default "subscribed" is grammatically inconsistent with the existing descriptions and will result in malformed notification text. The descriptions are meant to complete a sentence like "You [reason]".
Agent Prompt
Copy this prompt and use it to remediate the issue with your preferred AI generation tools
## Issue Description
The default notification reason text was changed to "subscribed", which is grammatically inconsistent with all other reason descriptions. All descriptions in GroupSubscriptionReason.descriptions are complete verb phrases that follow "You" in a sentence.
## Issue Context
The reason text is used in notification templates to explain why a user is receiving the notification. The format is "You [reason]". All existing reasons follow this pattern with complete verb phrases.
## Fix Focus Areas
- src/sentry/notifications/helpers.py[113-113]
|
|
||
| job["received_timestamp"] = job["event"].data.get("received") or float( | ||
| job["event"].datetime.strftime("%s") | ||
| job["event"].datetime.strftime("%s") if job["event"].datetime else 0 |
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.
3.Potential Type Error with Datetime □ 🐞 Bug
The change adds a check if job["event"].datetime else 0 to handle the case where datetime might be None. However, the Event.datetime property is defined as returning datetime (not Optional[datetime]), and the implementation at line 112-120 shows it will either return a datetime object or raise an exception (e.g., KeyError if 'timestamp' is missing from data). The property cannot return None. If datetime is missing or invalid, the code will raise an exception before reaching the conditional check, making the None check ineffective. Additionally, returning 0 as a fallback creates a type inconsistency - strftime returns a string, but 0 is an integer.
Agent Prompt
Copy this prompt and use it to remediate the issue with your preferred AI generation tools
## Issue Description
A None check was added for `job["event"].datetime`, but the datetime property cannot return None - it will raise an exception if the timestamp is missing. The check provides false confidence and doesn't actually handle the error case.
## Issue Context
The Event.datetime property is defined to return `datetime` type (not Optional[datetime]). If the timestamp is missing from event data, it will raise a KeyError at line 117 before any None check can execute.
## Fix Focus Areas
- src/sentry/event_manager.py[696-698]
Consider either:
1. Removing the None check and relying on existing error handling
2. Adding proper try-except around datetime access if missing timestamps need to be handled gracefully
| return { | ||
| item: { | ||
| "times_seen": times_seen.get(item.id, 0), | ||
| "times_seen": max(times_seen.get(item.id, 0), user_counts.get(item.id, 0)), |
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.
4. Times Seen Logic May Hide Issues □ 📎 Requirements Gap
The change modifies times_seen calculation from times_seen.get(item.id, 0) to max(times_seen.get(item.id, 0), user_counts.get(item.id, 0)). This ensures times_seen is never less than user_count, which makes logical sense (you can't have more unique users than total events). However, this change masks a potential data inconsistency issue. If user_counts exceeds times_seen, it indicates a bug in the data collection or aggregation logic that should be investigated and fixed at the source, rather than papered over with a max() call. The fix treats the symptom rather than the root cause.
Agent Prompt
Copy this prompt and use it to remediate the issue with your preferred AI generation tools
## Issue Description
The max() call ensures times_seen is never less than user_count, which is logically correct. However, if this condition occurs in the data, it indicates a bug in event/user counting that should be investigated.
## Issue Context
The times_seen value comes from tagstore queries, while user_counts comes from a separate query. If user_counts > times_seen, it suggests data inconsistency in how events or users are being tracked.
## Fix Focus Areas
- src/sentry/api/serializers/models/group.py[869-869]
Consider adding:
```python
if user_counts.get(item.id, 0) > times_seen.get(item.id, 0):
logger.warning(
"user_count exceeds times_seen",
extra={"item_id": item.id, "user_count": user_counts.get(item.id, 0), "times_seen": times_seen.get(item.id, 0)}
)
```
PR Overview by Qodo
⏱️ Less than 10 minutes✅ ️100% Passing rules (18)📎 85% Requirements met (4)🛠️ Bug Fix✨ New FeatureThis PR fixes multiple bugs related to null safety and logic corrections in the Sentry codebase
Walkthroughs
Description
Diagram
Files
➀ src/sentry/api/serializers/models/group.py +1/-1
➁ src/sentry/event_manager.py +1/-1
➂ src/sentry/issues/ingest.py +1/-1
➃ src/sentry/notifications/helpers.py +1/-1
✨ New Feature> >src/sentry/notifications/helpers.py [34-67]➄ src/sentry/quotas/redis.py +1/-1
➅ static/app/views/issueDetails/groupSidebar.tsx +2/-2
>
🛠️ Bug Fix> >static/app/views/issueDetails/groupSidebar.tsx [234-289]