Skip to content

LookupError <ContextVar name='current_scope' default=None at 0x7f88232e1620> #4410

Closed

Description

@DusanMadar

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.13.0

Steps to Reproduce

Python 3.10
Django 4.2.20
Gunicorn 23.0.0

sentry_sdk.init(
    dsn=os.getenv("SENTRY_BE_DSN"),
    integrations=[DjangoIntegration(), RedisIntegration()],
    traces_sample_rate=0.0,
    send_default_pii=True,
    environment=os.getenv("APP_NAME"),
    release=os.getenv("COMMIT"),
)

Looks similar to #3724.

Expected Result

Exception is not raised.

Actual Result

Traceback (most recent call last):
  File "/app/.venv/python/lib/python3.10/site-packages/gunicorn/workers/gthread.py", line 346, in handle_request
    respiter.close()
  File "/app/.venv/python/lib/python3.10/site-packages/sentry_sdk/integrations/wsgi.py", line 235, in close
    with use_isolation_scope(self._scope):
  File "/app/.venv/python/lib/python3.10/contextlib.py", line 142, in __exit__
    next(self.gen)
  File "/app/.venv/python/lib/python3.10/site-packages/sentry_sdk/scope.py", line 1678, in use_isolation_scope
    _current_scope.reset(current_token)
LookupError: <ContextVar name='current_scope' default=None at 0x7f88232e1620>

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on May 21, 2025
  2. antonpirker commented on May 22, 2025

    @antonpirker
    Contributor

    Hey @DusanMadar, thanks for writing in.

    Can you try to disable the gthread workers in Gunicorn to see if the exception is also raised with the default workers?

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on May 22, 2025
  4. DusanMadar commented on May 23, 2025

    @DusanMadar
    Author

    Hey @antonpirker, thanks for a quick response.

    We'll discuss your proposal with the team. 👍

    Interestingly enough we use the same gunicorn setup, i.e. --threads arg and therefore gthread workers, with another Django app and we don't see this error there. However, the other app uses sentry-sdk = "==1.14.*".

  5. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on May 23, 2025
  6. antonpirker commented on May 26, 2025

    @antonpirker
    Contributor

    Hey! One more thing @DusanMadar do you use the propagate_hub or propagate_scope parameter in the ThreadingIntegration?

  7. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on May 26, 2025
  8. antonpirker commented on May 26, 2025

    @antonpirker
    Contributor

    Oh, @DusanMadar and can you try to use Sentry SDK 2.26.1 or preferably the latest version, because we changed something in our ThreadingIntegration. (See https://github.com/getsentry/sentry-python/pull/4281/files)

  9. 20 remaining items

  10. sentrivana commented on Jun 16, 2025

    @sentrivana
    Collaborator

    Hey, is there any update regarding trying out some of the things suggested here? Or possibly a repro? If yes please let us know.

  11. moved this to Waiting for: Community in GitHub Issues with 👀 3on Jun 16, 2025
  12. DusanMadar commented on Jun 16, 2025

    @DusanMadar
    Author

    Hey @sentrivana, not yet, unfortunately. We have a deadline till the end of this moth with a certain migration, so that has a higher priority. But the plan is to bump to latest sentry-sdk version and use the suggested config.
    Reproduction steps are very unlikely to be provided since we don't really understand what triggers this behavior.

  13. moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3on Jun 16, 2025
  14. sentrivana commented on Jun 17, 2025

    @sentrivana
    Collaborator

    Understood @DusanMadar, please update us when there's news. In the meantime I'm thinking that even if we can't repro this, we can at least mitigate by not letting it bubble all the way up. Will look into that.

  15. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 17, 2025
  16. sentrivana commented on Jun 17, 2025

    @sentrivana
    Collaborator

    Wrapped the errors so that they don't surface in #4481. There will probably be a release with this next week.

    It'd still be worthwhile to fix the underlying problem, so if there's any follow-ups, please let us know even if the issue is closed with the PR being merged.

  17. DusanMadar commented on Jul 14, 2025

    @DusanMadar
    Author

    FYI we've deployed latest SDK version and used integrations=[ThreadingIntegration(propagate_scope=False), ...], config as suggested above. 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions