fix: Respect exception autocapture default for contexts#680
Conversation
a083097 to
e0d83ca
Compare
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_contexts.py:163-238
**New tests should be parameterised**
The three new tests that manipulate module globals (`test_new_context_defaults_to_global_exception_autocapture_disabled`, `test_new_context_explicit_true_captures_when_global_autocapture_disabled`, `test_new_context_explicit_false_skips_capture_when_global_autocapture_enabled`) share an identical save/restore pattern and differ only in `posthog.enable_exception_autocapture`, the value passed to `capture_exceptions`, and whether `mock_capture` is expected to be called. Following the project's stated preference for parameterised tests, these three could be collapsed into a single `@pytest.mark.parametrize` (or `subTest`) loop covering `(global_setting, explicit_arg, expect_captured)` tuples, reducing boilerplate and making the intention of each case clearer.
Reviews (1): Last reviewed commit: "fix: Respect exception autocapture defau..." | Re-trigger Greptile |
posthog-python Compliance ReportDate: 2026-06-19 14:38:59 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
|
|
@PostHog/team-error-tracking can you check this? it makes sense to me but it might be a change in behavior if the global is disabled and relies on the current default value of |
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/test/test_contexts.py:167-171
**Missing `(True, None, True)` subTest case**
The test verifies that the global autocapture setting is respected, but omits the case where `global_setting=True` and `capture_exceptions` is not passed — the scenario that confirms the default inherits an *enabled* setting. With only the three current cases, a regression that always resolves to `False` would pass this test. Adding `(True, None, True)` closes that gap and satisfies the team's rule of expressing every required idea.
### Issue 2 of 2
posthog/test/test_contexts.py:207-224
**Single-sided custom-client test**
`test_new_context_defaults_to_custom_client_exception_autocapture_disabled` only tests `enable_exception_autocapture=False`. Following the same pattern applied to the global-setting test, this would benefit from also covering `enable_exception_autocapture=True` — confirming that a client context with autocapture enabled does capture the exception by default. The test could be turned into a short parameterised loop over `(False, False)` / `(True, True)` to express both sides OnceAndOnlyOnce.
Reviews (2): Last reviewed commit: "address pr review feedback" | Re-trigger Greptile |
ablaszkiewicz
left a comment
There was a problem hiding this comment.
Looks good. Thanks for finding and fixing this. I just don't think this is a patch
its not a new feat either, imo its like fixing a bug, what do you suggest? |
💡 Motivation and Context
Fixes #353.
Contexts previously captured exceptions by default even when exception autocapture was disabled globally or on a custom client. This made users opt out with
capture_exceptions=Falsefor every new context.💚 How did you test it?
uv run --extra test pytest -q posthog/test/test_contexts.py posthog/test/test_exception_capture.pyuv run pytest -q posthog/test/test_contexts.py posthog/test/test_exception_capture.pyuv run --extra dev ruff format --check posthog/contexts.py posthog/client.py posthog/__init__.py posthog/test/test_contexts.pyuv run --extra dev ruff check posthog/contexts.py posthog/client.py posthog/__init__.py posthog/test/test_contexts.pyuv run --extra dev python .github/scripts/test_check_public_api.pyuv run --extra dev make public_api_check📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Implemented with a delegated Pi worker agent in a dedicated worktree. The change keeps explicit
capture_exceptions=Trueandcapture_exceptions=Falsebehavior intact while making omitted values derive from the relevant global or client exception autocapture setting. A patch changeset was added manually forpypi/posthog, and the public API snapshot was updated for the intentional signature default/type change.