fix: Validate custom event UUIDs#679
Merged
Merged
Conversation
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
posthog/client.py:120-124
The error message in the falsy-string branch doesn't include the actual value, while the second branch does. When `uuid=""` is passed, the caller sees a generic message with no indication of what was supplied, making it harder to debug than the `"not-a-uuid"` case.
```suggestion
stringified = stringify_id(value)
if not stringified:
raise ValueError(
f"Invalid event uuid {value!r}. Expected a valid UUID string or uuid.UUID instance."
)
```
### Issue 2 of 2
posthog/test/test_client.py:234-263
Per the team's review standards, parameterised tests are always preferred. `test_capture_with_invalid_uuid_logs_and_does_not_send` and `test_capture_with_invalid_uuid_raises_in_debug` each exercise only a single invalid input (`"not-a-uuid"`). A `@parameterized.expand` over a range of bad values (e.g. `""`, `"not-a-uuid"`, `"1234"`, `123`) would give more coverage and follows the existing pattern already used elsewhere in this file.
Reviews (1): Last reviewed commit: "fix: validate custom event UUIDs" | Re-trigger Greptile |
Contributor
posthog-python Compliance ReportDate: 2026-06-19 12:53:44 UTC ✅ All Tests Passed!45/45 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 16/16 tests passed View Details
|
a823e3a to
1e284ba
Compare
marandaneto
commented
Jun 19, 2026
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
posthog/args.py:65-67
The phrase "ignored" implies silent behavior, but invalid UUIDs are actually logged at ERROR level (`self.log.error(...)`) before the fallback UUID is generated. ERROR-level logs can trigger production alerting. This same wording appears in `__init__.py` (three times) and `client.py` (five docstrings). Replacing "ignored" with "trigger an error log and" more accurately describes what callers can expect.
```suggestion
UUID is returned, so you can correlate it with actions in your app. If provided,
it must be a valid UUID string or uuid.UUID instance; invalid values trigger an
error log and are replaced with a newly generated UUID.
```
### Issue 2 of 2
posthog/client.py:1117-1124
The `group_identify` signature was updated to `Optional[Union[str, UUID]]` in this PR, but the `alias` method's `uuid` parameter is still untyped. Since the docstring for `alias.uuid` was updated to document the same UUID validation behavior, the type annotation should match for consistency.
```suggestion
def alias(
self,
previous_id: str,
distinct_id: Optional[str],
timestamp=None,
uuid: Optional[Union[str, UUID]] = None,
disable_geoip=None,
):
```
Reviews (2): Last reviewed commit: "docs: document custom UUID fallback beha..." | Re-trigger Greptile |
ioannisj
approved these changes
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
Fixes #153.
Invalid custom event UUIDs were previously passed through to ingestion, which could surface as a generic backend 400 response. This validates user-provided event UUIDs client-side so invalid values fail before upload with a descriptive error/log message, while valid UUID strings and
uuid.UUIDobjects remain supported.💚 How did you test it?
uv run --extra test pytest -q posthog/test/test_client.pyuv run --extra dev ruff check posthog/client.py posthog/args.py posthog/test/test_client.pyuv run pytest -q posthog/test/test_client.py📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
A coding agent implemented the focused fix requested for issue #153 in an isolated worktree. The change is intentionally scoped to client-side UUID validation before events are queued or uploaded; it preserves generated UUID behavior when no UUID is supplied and accepts both valid UUID strings and
uuid.UUIDvalues.