fix: Generate UUID v7 identifiers#683
Draft
marandaneto wants to merge 2 commits into
Draft
Conversation
Contributor
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
posthog/test/test_uuid_utils.py:6-12
**Fallback path not explicitly tested**
`test_uuid7_generates_version_7_uuid_string` exercises whichever branch the current Python runtime enters — on 3.14+ only the stdlib path runs; the hand-rolled RFC 9562 implementation is exercised only on older Pythons. A bug in the fallback (e.g. wrong bit-shift for `rand_a`) would pass in CI if tests are run under Python 3.14+. The project also prefers parameterised tests; adding a fixture that patches `uuid.uuid7` away would ensure both paths are always validated, regardless of the runtime used in CI.
Reviews (1): Last reviewed commit: "fix: generate UUID v7 identifiers" | Re-trigger Greptile |
marandaneto
commented
Jun 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
SDK-generated identifiers should use UUID v7 so event UUIDs, personless fallback
distinct_ids, and AI telemetry trace/span IDs are time-sortable and consistent with other PostHog SDKs.💚 How did you test it?
uv run --extra test pytest posthog/test/test_uuid_utils.py posthog/test/test_client.py::TestClient::test_basic_capture posthog/test/test_client.py::TestClient::test_capture_without_distinct_id_generates_uuid_v7_personless_distinct_id posthog/test/ai/test_uuid_generation.pyuv run --extra test python -m compileall -q posthog/client.py posthog/_uuid.py posthog/aiuvx ruff check posthog/_uuid.py posthog/client.py posthog/ai/openai/openai.py posthog/ai/openai/openai_async.py posthog/ai/anthropic/anthropic.py posthog/ai/anthropic/anthropic_async.py posthog/ai/gemini/gemini.py posthog/ai/gemini/gemini_async.py posthog/ai/claude_agent_sdk/client.py posthog/ai/claude_agent_sdk/processor.py posthog/ai/utils.py posthog/test/test_client.py posthog/test/test_uuid_utils.py posthog/test/ai/test_uuid_generation.pyuvx ruff format --check posthog/_uuid.py posthog/client.py posthog/ai/openai/openai.py posthog/ai/openai/openai_async.py posthog/ai/anthropic/anthropic.py posthog/ai/anthropic/anthropic_async.py posthog/ai/gemini/gemini.py posthog/ai/gemini/gemini_async.py posthog/ai/claude_agent_sdk/client.py posthog/ai/claude_agent_sdk/processor.py posthog/ai/utils.py posthog/test/test_client.py posthog/test/test_uuid_utils.py posthog/test/ai/test_uuid_generation.pyuv run --extra dev python .github/scripts/check_public_api.py📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
An implementation agent updated Python SDK-generated UUID fallbacks to use a private UUID v7 helper. The helper uses Python 3.14+
uuid.uuid7()when available and otherwise falls back to a local RFC 9562-compatible implementation for supported older Python versions.A changeset file was added manually because this is a patch-level SDK behavior fix.