Skip to content

fix: Generate UUID v7 identifiers#683

Draft
marandaneto wants to merge 2 commits into
PostHog:mainfrom
marandaneto:fix/use-uuid-v7
Draft

fix: Generate UUID v7 identifiers#683
marandaneto wants to merge 2 commits into
PostHog:mainfrom
marandaneto:fix/use-uuid-v7

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 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.py
  • uv run --extra test python -m compileall -q posthog/client.py posthog/_uuid.py posthog/ai
  • uvx 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.py
  • uvx 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.py
  • uv run --extra dev python .github/scripts/check_public_api.py

📝 Checklist

  • 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

  • Ran sampo add to 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.

@marandaneto marandaneto self-assigned this Jun 19, 2026
@greptile-apps

greptile-apps Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix 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

Comment thread posthog/test/test_uuid_utils.py Outdated
Comment thread posthog/_uuid.py
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.

1 participant