Skip to content

fix: handle None rate_limit_timeout in disable_for_rate_limit(). Clos…#3378

Open
HarshitPal25 wants to merge 2 commits intointelowlproject:developfrom
HarshitPal25:fix/rate-limit-timeout-none
Open

fix: handle None rate_limit_timeout in disable_for_rate_limit(). Clos…#3378
HarshitPal25 wants to merge 2 commits intointelowlproject:developfrom
HarshitPal25:fix/rate-limit-timeout-none

Conversation

@HarshitPal25
Copy link

@HarshitPal25 HarshitPal25 commented Feb 26, 2026

Description

OrganizationPluginConfiguration.disable_for_rate_limit() crashes with a TypeError
when rate_limit_timeout is None (not configured). This PR adds a guard to handle
that case gracefully.

Closes #3366

Type of change

  • Bug fix (non-breaking change which fixes an issue).

Checklist

  • I have read and understood the rules about how to Contribute to this project
  • The pull request is for the branch develop
  • Linters (Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.

Copilot AI review requested due to automatic review settings February 26, 2026 16:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a crash in OrganizationPluginConfiguration.disable_for_rate_limit() that occurs when rate_limit_timeout is None. The method previously attempted to add a datetime and None together, causing a TypeError and leaving plugins permanently disabled without any automated recovery mechanism.

Changes:

  • Added guard clause to handle None/empty rate_limit_timeout before attempting datetime arithmetic
  • Logs warning when rate_limit_timeout is not configured
  • Sets informative disabled_comment explaining manual re-enable is required

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"Disabling the plugin, but no re-enable task will be scheduled."
)
self.disabled_comment = (
f"Rate limit hit at {now().strftime('%d %m %Y: %H %M %S')}.\n"
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The date format used here ('%d %m %Y: %H %M %S') is inconsistent with the format used in disable_manually() and enable_manually() methods in the same class (lines 1130 and 1142), which use '%Y-%m-%d %H:%M:%S'. While this format is consistent with the existing disable_for_rate_limit() code on lines 1095 and 1097, there's a broader inconsistency within the OrganizationPluginConfiguration class that should be addressed for maintainability. Consider standardizing the date format across all methods in this class to '%Y-%m-%d %H:%M:%S' which is the ISO 8601 standard format and more widely used throughout the codebase.

Copilot uses AI. Check for mistakes.
Comment on lines 1080 to 1090
if not self.rate_limit_timeout:
logger.warning(
f"{self} hit a rate limit but rate_limit_timeout isn't configured. "
"Disabling the plugin, but no re-enable task will be scheduled."
)
self.disabled_comment = (
f"Rate limit hit at {now().strftime('%d %m %Y: %H %M %S')}.\n"
"No re-enable timeout was configured — please re-enable manually."
)
self.save()
return
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix correctly handles the case when rate_limit_timeout is None, but there's no test coverage for this scenario. The existing test in tests/api_app/test_models.py (test_disable_for_rate_limit) only tests the case where rate_limit_timeout has a value (datetime.timedelta(minutes=1)). Consider adding a test case that verifies the behavior when rate_limit_timeout is None to ensure the fix works as expected and prevents regressions.

Copilot uses AI. Check for mistakes.
When rate_limit_timeout is None, the plugin is now disabled gracefully without scheduling a re-enable task. This prevents errors and improves reliability.

Changes:
• Standardized date format across all rate limit methods to ISO 8601 format ('%Y-%m-%d %H:%M:%S') for consistency with disable_manually() and enable_manually()
• Added test case for disable_for_rate_limit() when rate_limit_timeout is None to ensure proper behavior and prevent regressions
• Follows project standards and passes all linting checks
@HarshitPal25
Copy link
Author

PTAL @mlodic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants