Skip to content

Commit

Permalink
#4589 Adding a context to make SAC record accessible anywhere needed
Browse files Browse the repository at this point in the history
  • Loading branch information
sambodeme committed Jan 10, 2025
1 parent ed9369f commit 67b4035
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions backend/audit/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import contextvars
from contextlib import contextmanager


current_sac = contextvars.ContextVar("current_sac", default=None)


@contextmanager
def set_sac_to_context(sac):
reference = current_sac.set(sac)
try:
yield
finally:
current_sac.reset(reference)


def get_sac_from_context():
return current_sac.get(None)

0 comments on commit 67b4035

Please sign in to comment.