feat: create new task for organization contributor reset#104259
feat: create new task for organization contributor reset#104259ajay-sentry merged 2 commits intomasterfrom
Conversation
| Reset num_actions for all OrganizationContributors rows in the given organization. | ||
| """ | ||
| updated_count = ( | ||
| OrganizationContributors.objects.filter(organization_id=organization_id) | ||
| .exclude(num_actions=0) | ||
| .update(num_actions=0, date_updated=timezone.now()) | ||
| ) | ||
| logger.info( | ||
| "organization_contributors.reset_num_actions", | ||
| extra={"organization_id": organization_id, "rows_updated": updated_count}, | ||
| ) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
This is intended, just de-risking
srest2021
left a comment
There was a problem hiding this comment.
lgtm but would wait for a senior to review too :)
| @patch("sentry.tasks.organization_contributors.logger") | ||
| def test_resets_num_actions_for_all_contributors(self, mock_logger): | ||
| """Test that num_actions is reset to 0 for all contributors in organization.""" | ||
| contributor1 = OrganizationContributors.objects.create( |
There was a problem hiding this comment.
nit: could create a factory for OrganizationContributors in sentry/testutils/factories.py
There was a problem hiding this comment.
Fair enough, I don't think we'll be using this model all that much tbh but maybe I'll revisit if it gets more noisy
|
|
||
|
|
||
| @instrumented_task( | ||
| name="sentry.tasks.organization_contributors.reset_num_actions_for_organization", |
There was a problem hiding this comment.
nit to match the function name
| name="sentry.tasks.organization_contributors.reset_num_actions_for_organization", | |
| name="sentry.tasks.organization_contributors.reset_num_actions_for_organization_contributors", |
| Reset num_actions for all OrganizationContributors rows in the given organization. | ||
| """ | ||
| updated_count = ( | ||
| OrganizationContributors.objects.filter(organization_id=organization_id) | ||
| .exclude(num_actions=0) | ||
| .update(num_actions=0, date_updated=timezone.now()) | ||
| ) | ||
| logger.info( | ||
| "organization_contributors.reset_num_actions", | ||
| extra={"organization_id": organization_id, "rows_updated": updated_count}, | ||
| ) |
There was a problem hiding this comment.
Bug: The reset_num_actions_for_organization_contributors() task is implemented but never invoked.
Severity: HIGH | Confidence: High
🔍 Detailed Analysis
The reset_num_actions_for_organization_contributors() task is implemented but is never invoked by any event handlers or scheduled tasks. The pull request description explicitly states this task should be triggered at trial end and billing period start, but no code exists to call it at these intended trigger points. Consequently, the core functionality of resetting organization contributors will not be executed in production.
💡 Suggested Fix
Implement the necessary event handlers or scheduled tasks to invoke reset_num_actions_for_organization_contributors() at trial end and billing period start events as intended.
🤖 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/tasks/organization_contributors.py#L20-L32
Potential issue: The `reset_num_actions_for_organization_contributors()` task is
implemented but is never invoked by any event handlers or scheduled tasks. The pull
request description explicitly states this task should be triggered at trial end and
billing period start, but no code exists to call it at these intended trigger points.
Consequently, the core functionality of resetting organization contributors will not be
executed in production.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 4998952
This PR aims to create a new task to be spawned in 2 places:
which will reset the organization contributors for a sentry org and all it's respective integrations to 0.
Closes https://linear.app/getsentry/issue/ENG-5940/create-new-job-for-updating-num-actions-rows-to-0-for-an-org
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.