Repository navigation
Open
Labels
BugJunior: reproJunior reproduces this bug and drafts a fixJunior reproduces this bug and drafts a fixPythonSDKSDK
Description
tests/integrations/django/test_cache_module.py::test_cache_spans_item_size[True] and ::test_cache_spans_decorator[True] fail intermittently on master in streaming mode (span_streaming=True). Both tests make two requests, one trace each, and index the captured spans by position. Sometimes request 2's spans arrive first.
Failure
tests/integrations/django/test_cache_module.py:763: in test_cache_spans_item_size
assert not spans[0]["attributes"]["cache.hit"]
E assert not True
test_cache_spans_decorator[True] fails the same way at line 384.
Expected vs actual
- Expected:
spans[0]is request 1'scache.get, a miss. - Actual:
spans[0]is request 2'scache.get, a hit.len(spans) == 7still passes; only the order across the two traces changes.
CI failures on master (Sep 30 – Oct 13, 6 of 33 Test runs)
test_cache_spans_item_size[True]: py3.14 django-v6.1.2,916942d(job); py3.14 django-v6.1.1,b5737a0(job); py3.14 django-v6.1.1,8afefe8(job)test_cache_spans_decorator[True]: py3.12 django-v4.2.30,6a4eb20(job); py3.14 django-v5.2.17,bf1e2f9(job); py3.10 django-v5.2.17,8012047(job)- Always the
Web 1job, always[True](streaming). It appears on Django 4.2 through 6.1 and Python 3.10 through 3.14.
Known trigger
- In streaming mode, each finished segment adds its
trace_idtoSpanBatcher._pending_flush, which is aset(sentry_sdk/_span_batcher.py). Pending flushing was added in ref: Flush trace buckets when segment spans finish #7170. - If the background flusher wakes only after both requests' segments have finished,
list(self._pending_flush)sends the two traces in set (hash) order instead of the order they finished. That happens about 50% of the time once both are pending. - On an idle machine the flusher usually sends request 1 before request 2 ends. A busy CI runner delays the flusher thread, so both end up pending.
- test(django): Fix flaky cache tests by using uuid for cache LOCATION #7444 (uuid
LOCATIONfor the cache) fixed a different flake in these tests. These failures all happened after it was merged.
via johdax.
--
Reacted by sentry-junior
Metadata
Metadata
Assignees
Labels
BugJunior: reproJunior reproduces this bug and drafts a fixJunior reproduces this bug and drafts a fixPythonSDKSDK
Projects
- StatusShow more project fieldsNo status
Activity
linear-code commentedon Oct 14, 2026
PY-3001
sentry-junior commentedon Oct 14, 2026
Minimal reproduction (no Django): getsentry/repro#61. About 49% of iterations send the second trace's spans first when both segments are pending at the same time.
sentry-junior commentedon Nov 12, 2026
Reproduced in getsentry/repro#61. Draft fix: #8261, waiting for review.