Skip to content
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

fix(integrations): Handle missing default org owner in metric #87042

Merged
merged 2 commits into from
Apr 3, 2025

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Mar 13, 2025

In our sync_status_inbound integrations task, we record a metric which includes the user id of the org's owner. This can crash if we can't find an owner - in Organization.get_default_owner, we try to return the first owner, but that raises an index error if the owner list is empty.

Since the value is only being used for a metric, we don't want retrieving it to make the whole task error out. This therefore wraps the code getting the value in a try-except, and sets the value to None if the index error is raised. Since this is really just a bandaid (orgs should always have an owner, shouldn't they?), it also adds a TODO for investigating how there can be no owners.

Fixes https://sentry.sentry.io/issues/4069184744.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 13, 2025
@lobsterkatie lobsterkatie marked this pull request as ready for review March 13, 2025 22:18
@lobsterkatie lobsterkatie requested review from a team as code owners March 13, 2025 22:18
@cathteng cathteng requested a review from GabeVillalobos March 13, 2025 22:19
analytics.record(
"issue.resolved",
project_id=group.project.id,
default_user_id=organizations[0].get_default_owner().id,
default_user_id=default_user_id,
Copy link
Member

Choose a reason for hiding this comment

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

Is this field allowed to be falsey? Assuming this is the correct definition, analytics for this event appears to have it defaulted to required:

analytics.Attribute("default_user_id"),

Maybe we can toggle this to required = False in this PR as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I have no idea. analytics is amplitude, right? I've never used it - didn't even know those metrics came with a schema! Happy to make that change after the meeting I'm about to run into.

Copy link
Member

Choose a reason for hiding this comment

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

I believe so! And sounds good, thank you!

Copy link
Member Author

@lobsterkatie lobsterkatie Mar 17, 2025

Choose a reason for hiding this comment

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

I was trying to figure out if setting the value to None was the same as not providing a value ("not required" and "can be null" could conceivably mean different things), and noticed that you also need to specify type, which might have had to change... So in the end I decided it was easier to leave the schema as is and just set the value to <unknown>. (I know id is a number, but it must get stringified, because the default type is str and that property in the schema (to which you linked) doesn't specify type, so it must also be str. That said, to satisfy mypy, I had to explicitly stringify it.)

LMK if that solution works, and if not, I'll figure out about the null vs missing question and modify the schema appropriately.

Copy link
Member

Choose a reason for hiding this comment

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

Good call out, that works! We can circle back on this if we notice any issues with analytics for this event.

Copy link

codecov bot commented Mar 14, 2025

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...c/sentry/integrations/tasks/sync_status_inbound.py 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #87042      +/-   ##
==========================================
- Coverage   87.78%   87.74%   -0.05%     
==========================================
  Files        9853     9847       -6     
  Lines      558951   557050    -1901     
  Branches    21966    21966              
==========================================
- Hits       490686   488778    -1908     
- Misses      67835    67842       +7     
  Partials      430      430              

@lobsterkatie lobsterkatie merged commit 4e5e91b into master Apr 3, 2025
49 checks passed
@lobsterkatie lobsterkatie deleted the kmclb-fix-sync-status-user-id-error branch April 3, 2025 16:13
andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
In our `sync_status_inbound` integrations task, we record a metric which includes the user id of the org's owner. This can crash if we can't find an owner - in `Organization.get_default_owner`, we try to return the first owner, but that raises an index error if the owner list is empty. 

Since the value is only being used for a metric, we don't want retrieving it to make the whole task error out. This therefore wraps the code getting the value in a `try-except`, and sets the value to `None` if the index error is raised. Since this is really just a bandaid (orgs should always have an owner, shouldn't they?), it also adds a TODO for investigating how there can be no owners.

Fixes https://sentry.sentry.io/issues/4069184744.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants