Skip to content

ref(analytics): Transform analytics events for TET-837 #95216

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

constantinius
Copy link
Contributor

  • Transform event classes to use @analytics.eventclass decorator
  • Transform analytics.record calls to use event class instances
  • Update imports as needed

Closes TET-837

- Transform event classes to use @analytics.eventclass decorator
- Transform analytics.record calls to use event class instances
- Update imports as needed

Closes TET-837
@constantinius constantinius requested review from a team as code owners July 10, 2025 09:17
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 10, 2025
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: String Annotations with Integer Values

creator_id and owner_id are annotated as str but integer user IDs (e.g., request.user.id, owner.id) are passed directly, causing a type mismatch.

src/sentry/analytics/events/relocation_created.py#L5-L7

class RelocationCreatedEvent(analytics.Event):
creator_id: str
owner_id: str

src/sentry/analytics/events/relocation_forked.py#L5-L7

class RelocationForkedEvent(analytics.Event):
creator_id: str
owner_id: str

Fix in CursorFix in Web


Bug: Refactor Issues: Type Mismatch, Inconsistent Event Class Usage

The refactor of UserSignUpEvent introduced two issues:

  1. The user_id attribute is typed as str, but an integer user.id is passed by calling code, causing a type mismatch.
  2. RelocationUserSignUpEvent inherits from UserSignUpEvent but inconsistently uses the old type attribute instead of the new @analytics.eventclass decorator pattern.

src/sentry/analytics/events/user_signup.py#L5-L13

class UserSignUpEvent(analytics.Event):
user_id: str
source: str
provider: str | None = None
referrer: str | None = None
class RelocationUserSignUpEvent(UserSignUpEvent):
type = "relocation.user_signup"

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

Copy link

codecov bot commented Jul 10, 2025

❌ 27 Tests Failed:

Tests completed Failed Passed Skipped
27175 27 27148 242
View the top 3 failed test(s) by shortest run time
tests.sentry.relocation.api.endpoints.test_retry.RetryRelocationTest::test_good_simple
Stack Traces | 0.721s run time
#x1B[1m#x1B[.../api/endpoints/test_retry.py#x1B[0m:126: in test_good_simple
    analytics_record_mock.assert_called_with(
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/unittest/mock.py#x1B[0m:977: in assert_called_with
    raise AssertionError(_error_message()) from cause
#x1B[1m#x1B[31mE   AssertionError: expected call not found.#x1B[0m
#x1B[1m#x1B[31mE   Expected: record('relocation.created', creator_id=637, owner_id=637, uuid='224bf00f-836a-4625-adbe-6bab0d424f1e')#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(RelocationCreatedEvent(uuid_=UUID('016dd83c-5d70-11f0-b894-00224808b7a5'), datetime_=datetime.datetime(2025, 7, 10, 9, 26, 49, 533528, tzinfo=datetime.timezone.utc), creator_id='637', owner_id='637', uuid='224bf00f-836a-4625-adbe-6bab0d424f1e'))#x1B[0m
tests.sentry.relocation.api.endpoints.test_retry.RetryRelocationTest::test_good_superuser_when_feature_disabled
Stack Traces | 0.728s run time
#x1B[1m#x1B[.../api/endpoints/test_retry.py#x1B[0m:204: in test_good_superuser_when_feature_disabled
    analytics_record_mock.assert_called_with(
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/unittest/mock.py#x1B[0m:977: in assert_called_with
    raise AssertionError(_error_message()) from cause
#x1B[1m#x1B[31mE   AssertionError: expected call not found.#x1B[0m
#x1B[1m#x1B[31mE   Expected: record('relocation.created', creator_id=717, owner_id=716, uuid='9773ce92-1b88-40de-8fd8-be29a9a6baac')#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(RelocationCreatedEvent(uuid_=UUID('e578b9c1-5d6f-11f0-b894-7ced8d56a323'), datetime_=datetime.datetime(2025, 7, 10, 9, 26, 3, 356806, tzinfo=datetime.timezone.utc), creator_id='717', owner_id='716', uuid='9773ce92-1b88-40de-8fd8-be29a9a6baac'))#x1B[0m
tests.sentry.relocation.api.endpoints.test_retry.RetryRelocationTest::test_good_staff_when_feature_disabled
Stack Traces | 0.818s run time
#x1B[1m#x1B[.../api/endpoints/test_retry.py#x1B[0m:166: in test_good_staff_when_feature_disabled
    analytics_record_mock.assert_called_with(
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/unittest/mock.py#x1B[0m:977: in assert_called_with
    raise AssertionError(_error_message()) from cause
#x1B[1m#x1B[31mE   AssertionError: expected call not found.#x1B[0m
#x1B[1m#x1B[31mE   Expected: record('relocation.created', creator_id=615, owner_id=613, uuid='edae1ab0-cd85-4e43-9b24-13f8624ecf73')#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(RelocationCreatedEvent(uuid_=UUID('faebc814-5d6f-11f0-b894-0022480b7330'), datetime_=datetime.datetime(2025, 7, 10, 9, 26, 39, 350239, tzinfo=datetime.timezone.utc), creator_id='615', owner_id='613', uuid='edae1ab0-cd85-4e43-9b24-13f8624ecf73'))#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

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.

1 participant