Skip to content

Fix last_event_id() in nested scopes #3114

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

Closed
wants to merge 1 commit into from

Conversation

adamchainz
Copy link
Contributor

@adamchainz adamchainz commented May 30, 2024

Fixes #3113.

I added two tests, one that generally checks Scope.__copy__() copies everything that it should, and one top-level one that reproduces the bug seen. On master, both fail with:

AttributeError: 'Scope' object has no attribute '_last_event_id'. Did you mean: 'last_event_id'?

@szokeasaurusrex please take a look :)

@sl0thentr0py
Copy link
Member

sl0thentr0py commented May 31, 2024

@antonpirker assigning this to you since I'm not sure what the desired semantics here should be (since it only should be on the isolation scope and so on..)

Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! I have requested a few changes, please see my comments.

Comment on lines -211 to -213
# self._last_event_id is only applicable to isolation scopes
self._last_event_id = None # type: Optional[str]

Copy link
Member

Choose a reason for hiding this comment

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

While I agree that it likely makes sense to move these lines to the clear function, I believe this change should be considered in a separate PR, since it does not appear to be needed to fix #3113; the tests you added pass even if I undo this change.

Comment on lines +679 to +681
# self._last_event_id is only applicable to isolation scopes
self._last_event_id = None # type: Optional[str]

Copy link
Member

Choose a reason for hiding this comment

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

Likely belongs in separate PR, see previous comment.

Comment on lines +28 to +31
# Check all attributes are copied
for name in set(Scope.__slots__) - {"client"}:
getattr(s2, name)

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to add this check to a separate unit test, since it is somewhat unrelated to the tag copying checks that this existing test is checking. The comment should also be updated to something like "Check that all attributes, except client, are present on the new scope", as the check only verifies the attributes' presence, and does not check whether the values were actually copied.

sentry_init(enable_tracing=True)

# Should not crash
with push_scope() as scope:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
with push_scope() as scope:
with isolation_scope() as scope:

push_scope is deprecated since version 2.0.0, so let's use the new isolation_scope function here, instead. Using isolation_scope also fails on master but passes on this branch.

@szokeasaurusrex
Copy link
Member

@sl0thentr0py, removing @antonpirker's assignment since I have already reviewed – I wrote the original Scope-based last_event_id implementation (#3064), so I am familiar with this code

@szokeasaurusrex
Copy link
Member

Closing in favor of #3123, which is based on this PR, but includes the changes I requested here

@szokeasaurusrex
Copy link
Member

szokeasaurusrex commented Jun 3, 2024

Also, I split your changes to clear _last_event_id in the clear method into #3124 @adamchainz

@adamchainz
Copy link
Contributor Author

Thank you for the fix. I didn’t have to look at this because I wasn’t working on the related contract.

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.

last_event_id() crash: AttributeError: 'Scope' object has no attribute '_last_event_id'.
4 participants