Skip to content

feat: create new task for organization contributor reset#104259

Merged
ajay-sentry merged 2 commits intomasterfrom
Ajay/5940-org-cont-reset-task
Dec 2, 2025
Merged

feat: create new task for organization contributor reset#104259
ajay-sentry merged 2 commits intomasterfrom
Ajay/5940-org-cont-reset-task

Conversation

@ajay-sentry
Copy link
Copy Markdown
Contributor

This PR aims to create a new task to be spawned in 2 places:

  • Trial end
  • billing period start

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.

@linear
Copy link
Copy Markdown

linear bot commented Dec 2, 2025

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 2, 2025
Comment on lines +22 to +32
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is intended, just de-risking

Copy link
Copy Markdown
Member

@srest2021 srest2021 left a comment

Choose a reason for hiding this comment

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

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(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: could create a factory for OrganizationContributors in sentry/testutils/factories.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit to match the function name

Suggested change
name="sentry.tasks.organization_contributors.reset_num_actions_for_organization",
name="sentry.tasks.organization_contributors.reset_num_actions_for_organization_contributors",

Comment on lines +22 to +32
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},
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@ajay-sentry ajay-sentry merged commit 89aee62 into master Dec 2, 2025
66 checks passed
@ajay-sentry ajay-sentry deleted the Ajay/5940-org-cont-reset-task branch December 2, 2025 22:28
@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants