Skip to content

Commit d9118c0

Browse files
committed
Merge branch '3528-the-local-cache-is-not-invalidated-properly-in-celery-tasks' into 'develop'
Resolve "The local cache is not invalidated properly in celery tasks" Closes #3528 See merge request baserow/baserow!3310
2 parents d55b3f9 + 891d39a commit d9118c0

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

backend/src/baserow/config/celery.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
from celery import Celery
1+
from celery import Celery, signals
2+
3+
from baserow.core.cache import local_cache
24

35
app = Celery("baserow")
46
app.config_from_object("django.conf:settings", namespace="CELERY")
57
app.autodiscover_tasks()
8+
9+
10+
def clear_local_cache(*args, **kwargs):
11+
"""
12+
Clear the thread-local cache before and after each Celery task to prevent
13+
data leakage between tasks running on the same worker thread.
14+
"""
15+
16+
local_cache.clear()
17+
18+
19+
signals.task_prerun.connect(clear_local_cache)
20+
signals.task_postrun.connect(clear_local_cache)

backend/src/baserow/core/jobs/tasks.py

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from django.conf import settings
44

55
from baserow.config.celery import app
6-
from baserow.core.cache import local_cache
76
from baserow.core.jobs.exceptions import JobCancelled
87
from baserow.core.jobs.registries import job_type_registry
98
from baserow.core.sentry import setup_user_in_sentry
@@ -15,7 +14,6 @@
1514
queue="export",
1615
soft_time_limit=settings.BASEROW_JOB_SOFT_TIME_LIMIT,
1716
)
18-
@local_cache.context()
1917
def run_async_job(self, job_id: int):
2018
"""Run the job task asynchronously"""
2119

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"type": "bug",
3+
"message": "Clear local_cache for celery tasks",
4+
"domain": "core",
5+
"issue_number": 3528,
6+
"bullet_points": [],
7+
"created_at": "2025-03-26"
8+
}

0 commit comments

Comments
 (0)