Skip to content

fix: keep frozenset and deque values when cleaning event properties - #1230

Merged
ioannisj merged 1 commit into
PostHog:mainfrom
Ishkirat-Singh:fix/clean-frozenset-deque
Nov 12, 2026
Merged

ioannisj merged 1 commit into
PostHog:mainfrom
Ishkirat-Singh:fix/clean-frozenset-deque

Conversation

@Ishkirat-Singh

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

utils.clean() runs on every captured event. It turns set, list and tuple values into lists, but frozenset and collections.deque don't match that check, fall through to _coerce_unicode(), and come back as None. So a property sent as a frozenset or a deque is silently dropped to null, while the same data sent as a set or a list arrives intact:

from unittest import mock
from collections import deque
from posthog import Client

with mock.patch("posthog.client.batch_post") as post:
    client = Client("phc_test", sync_mode=True)
    client.capture("e", distinct_id="d", properties={"tags": {"a"}, "frozen": frozenset({"a"}), "recent": deque(["x"])})
    print(post.call_args[1]["batch"][0]["properties"])
# main:  'tags': ['a'], 'frozen': None, 'recent': None
# here:  'tags': ['a'], 'frozen': ['a'], 'recent': ['x']

The fix adds frozenset and deque to the container check in clean(), so they go through _clean_list() like the other containers and their items are cleaned the same way (Decimal to float, UUID to str, and so on). Nothing else changes: other unknown types still become None.

💚 How did you test it?

  • Extended test_clean_containers_and_invalid_dict_values in posthog/test/test_utils.py with a frozenset and a deque holding a Decimal and a UUID. It fails on main and passes with the fix.
  • Ran the capture snippet above against the real Client in sync_mode with only batch_post mocked: on main both properties arrive as None; with the fix they arrive as lists.
  • pytest posthog/test/test_utils.py --timeout=30: 106 passed, 2 skipped, 1 failed. The failure is TestFlagCache::test_lru_eviction, which fails the same way on an unchanged main on my Windows machine (the test relies on two consecutive time.time() calls returning different values, and Windows' clock resolution is coarser than that), so it isn't related to this change.
  • Full suite pytest --timeout=30 (Python 3.12, Windows 11): 6726 passed, 76 skipped, 6 failed. The same 6 tests fail on an unchanged main checkout in the same environment (test_client_fork x2 need os.register_at_fork, plus test_lru_eviction, the two Gemini basic-generation tests and test_basic_capture_exception_with_no_exception_given), so none of them come from this change.
  • ruff format --check, ruff check, mypy --no-site-packages --config-file mypy.ini posthog/utils.py | mypy-baseline filter and python -W error -c "import posthog" all pass.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Added a changeset file (.sampo/changesets/frozen-deque-clean.md, written in the format sampo add produces)

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

I directed the work and reviewed the diff; a Claude Code agent (Claude Opus) read posthog/utils.py, reproduced the dropped values through the real client, and wrote the fix, test and changeset. I kept the change to the two container types that sit next to set/list/tuple instead of widening the check to every iterable, because that would also catch bytes, bytearray, range and generators and change how they are sent today.

clean() turned set, list and tuple values into lists but sent frozenset
and deque values as None, so those properties were silently lost.
@Ishkirat-Singh
Ishkirat-Singh requested a review from a team as a code owner November 11, 2026 15:41
@ioannisj
ioannisj requested a review from a team November 11, 2026 19:38
@ioannisj

Copy link
Copy Markdown
Contributor

@PostHog/team-client-libraries wonder if it's worth updating sdk-specs for container values?

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

SDK performance: posthog-python

Benchmarks completed. No changes flagged for review.

Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate.

View all results
Test Measurement Before PR With PR Change Assessment
Capture and deliver events (32-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Queue an event (32-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (32-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Refresh 1,000 flag definitions
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocated memory per operation 113.97 KiB/op 113.97 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 1,104.58 count/op 1,104.53 count/op <0.1% fewer Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 113.02 µs/op 118.27 µs/op 4.6% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 36.09 MiB 36.12 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 37.8 MiB 37.83 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 37.8 MiB 37.83 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 113.32 µs/op 119.98 µs/op 5.9% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 40 MiB 40 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation 166.54 KiB/op 166.54 KiB/op <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 1,097.61 count/op 1,097.63 count/op <0.1% more Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 149.99 µs/op 158.73 µs/op 5.8% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 40.9 MiB 40.99 MiB 0.2% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 45.93 MiB 46.02 MiB 0.2% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 45.93 MiB 46.02 MiB 0.2% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 143.24 µs/op 148.1 µs/op 3.4% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 50.81 MiB 50.89 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 118.12 KiB/op 118.12 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 1,144.59 count/op 1,144.62 count/op <0.1% more Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 131.38 µs/op 132.35 µs/op 0.7% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 35.95 MiB 36.07 MiB 0.3% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 36.04 MiB 36.15 MiB 0.3% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 36.04 MiB 36.15 MiB 0.3% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 128.9 µs/op 131.82 µs/op 2.3% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40 MiB 40 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation 171.01 KiB/op 171.01 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 1,137.5 count/op 1,137.48 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 161.96 µs/op 159.9 µs/op 1.3% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 40.77 MiB 40.77 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 40.77 MiB 40.77 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 40.76 MiB 40.75 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 154.99 µs/op 151.25 µs/op 2.4% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.03 MiB 41.14 MiB 0.3% more memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 83.32 µs/op 91.64 µs/op 10% more time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 86 µs/op 91.66 µs/op 6.6% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 92.18 µs/op 88.44 µs/op 4.1% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 98.6 µs/op 92.56 µs/op 6.1% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation 200.98 KiB/op 200.98 KiB/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 2,339.33 count/op 2,339.33 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 104.57 µs/op 103.9 µs/op 0.6% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 104.55 µs/op 103.9 µs/op 0.6% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation 1.93 MiB/op 1.93 MiB/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 23,013.56 count/op 23,013.56 count/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 973.54 µs/op 976.65 µs/op 0.3% more time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 973.65 µs/op 976.67 µs/op 0.3% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation 19.24 MiB/op 19.24 MiB/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 229,654.94 count/op 229,654.94 count/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 9.8 ms/op 9.78 ms/op 0.2% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 9.8 ms/op 9.78 ms/op 0.2% less time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 42.37 MiB 42.45 MiB 0.2% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 42.73 MiB 42.78 MiB 0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 42.73 MiB 42.78 MiB 0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 42.6 MiB 42.6 MiB No observed change Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 41.41 MiB 41.82 MiB 1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 42.15 MiB 42.16 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 42.13 MiB 41.86 MiB 0.6% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 42.49 MiB 42.5 MiB <0.1% more memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation 15.06 KiB/op 15.06 KiB/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 173.76 count/op 173.76 count/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Time per operation 14.07 µs/op 14.02 µs/op 0.3% less time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 14.06 µs/op 14.03 µs/op 0.3% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation 23.14 KiB/op 23.14 KiB/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 270.27 count/op 270.27 count/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 21.68 µs/op 21.82 µs/op 0.6% more time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 21.68 µs/op 21.82 µs/op 0.6% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation 35.73 KiB/op 35.73 KiB/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 387.27 count/op 387.27 count/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Time per operation 27.38 µs/op 27.46 µs/op 0.3% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 27.37 µs/op 27.46 µs/op 0.3% more time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation 53.61 KiB/op 53.61 KiB/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 576.27 count/op 576.27 count/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 38.15 µs/op 38.65 µs/op 1.3% more time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 38.14 µs/op 38.65 µs/op 1.3% more time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation 52.16 KiB/op 52.16 KiB/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 556.77 count/op 556.77 count/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 35.06 µs/op 34.96 µs/op 0.3% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 35.06 µs/op 34.96 µs/op 0.3% less time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation 17.85 KiB/op 17.85 KiB/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 198.27 count/op 198.27 count/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 16.81 µs/op 16.62 µs/op 1.1% less time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 16.81 µs/op 16.62 µs/op 1.1% less time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation 19.24 KiB/op 19.24 KiB/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 210.77 count/op 210.77 count/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 17.42 µs/op 17.26 µs/op 0.9% less time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 17.42 µs/op 17.26 µs/op 0.9% less time Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation 14.05 KiB/op 14.05 KiB/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 160.76 count/op 160.76 count/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Time per operation 13.05 µs/op 13.07 µs/op 0.1% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 13.05 µs/op 13.07 µs/op 0.1% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation 15.22 KiB/op 15.22 KiB/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 177.77 count/op 177.77 count/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Time per operation 14.52 µs/op 14.5 µs/op 0.1% less time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 14.52 µs/op 14.5 µs/op 0.2% less time Not flagged

Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals.

Each shard uses its own runner; compare Before PR against With PR within a row, not across shards.

Compared b182023e33bf3ef6bd9c388c80cd96eff936a9de → 140f766012a3803fdfaf9be02fafc9e0fcaa79ba.

Full report and diagnostics

102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in comparison.json, including per-runner environments, resource limits, measurement methods, samples and checkpoints.

@ioannisj
ioannisj merged commit 5378ece into PostHog:main Nov 12, 2026
54 of 56 checks passed
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.

2 participants