-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(uptime): Move subscription limit check to validator #100904
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
ref(uptime): Move subscription limit check to validator #100904
Conversation
Move uptime subscription limit checking from exception handling in create() to validator validation method. This ensures limits are checked during validation phase when creating new uptime monitors, providing consistent error responses and cleaner code. Follows the same pattern as cron monitors for consistency.
target_object=detector.id, | ||
event=audit_log.get_event_id("UPTIME_MONITOR_ADD"), | ||
data=get_audit_log_data(detector), | ||
) | ||
|
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.
Potential bug: The create
method no longer handles the MaxManualUptimeSubscriptionsReached
exception, which can be raised during a race condition, causing a 500 error instead of a validation error.
-
Description: The
create
method inUptimeMonitorValidator
no longer handles theMaxManualUptimeSubscriptionsReached
exception. This exception can be raised bycheck_uptime_subscription_limit
, which is called within the creation logic. While a limit check was added to thevalidate
method, a race condition can occur where concurrent requests cause the subscription limit to be exceeded between the validation and creation steps. Because thetry...except
block was removed from thecreate
method, this race condition will lead to an unhandled exception, resulting in a 500 Internal Server Error instead of the expected 400 Bad Request with a validation error. -
Suggested fix: Wrap the call to
super().create()
within thecreate
method in atry...except MaxManualUptimeSubscriptionsReached
block. In theexcept
block, raise aValidationError
to ensure subscription limit errors are handled gracefully as 400 responses, preventing 500 errors from race conditions.
severity: 0.65, confidence: 0.98
Did we get this right? 👍 / 👎 to inform future reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #100904 +/- ##
===========================================
- Coverage 81.15% 81.14% -0.01%
===========================================
Files 8615 8616 +1
Lines 382250 382254 +4
Branches 24033 24033
===========================================
- Hits 310199 310194 -5
- Misses 71723 71732 +9
Partials 328 328 |
Move uptime subscription limit checking from exception handling in
create() to validator validation method. This ensures limits are checked
during validation phase when creating new uptime monitors, providing
consistent error responses and cleaner code.
Follows the same pattern as cron monitors for consistency.