Skip to content

Conversation

@qbey
Copy link
Member

@qbey qbey commented Nov 5, 2025

Purpose

Posthog fixed their middleware in v6.7.14
This reverts commit fbe9e03.

see PostHog/posthog-python#358

Proposal

  • revert middleware patch
  • preserve the test added in reverted commit

Summary by CodeRabbit

  • Bug Fixes
    • Updated PostHog analytics middleware to resolve compatibility issues with async operations.

@qbey qbey self-assigned this Nov 5, 2025
@qbey qbey added the backend label Nov 5, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 5, 2025

Walkthrough

This pull request removes the asynchronous PostHog context middleware implementation and replaces it with the standard PostHog Django integration middleware. The async middleware class, helper methods, and associated logic are deleted, and the middleware configuration is updated to reference the standard implementation.

Changes

Cohort / File(s) Summary
PostHog async middleware removal
src/backend/core/posthog.py
Removed entire AsyncPosthogContextMiddleware class and async helper methods (extract_tags_async, extract_request_user_async, __acall__). Deleted async context extraction and PostHog context integration logic.
Middleware configuration update
src/backend/conversations/settings.py
Replaced middleware reference from core.posthog.AsyncPosthogContextMiddleware to posthog.integrations.django.PosthogContextMiddleware in Django MIDDLEWARE configuration.
Changelog documentation
CHANGELOG.md
Added "Removed" subsection entry documenting the removal of PostHog middleware with reference to issue #146.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Areas requiring attention:

  • Verify no other code references the removed AsyncPosthogContextMiddleware class or its async methods
  • Confirm the standard PostHog Django middleware provides equivalent functionality for the application's requirements
  • Ensure test suite passes with the middleware replacement

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: removing PostHog async middleware, which aligns with all file modifications in the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch qbey/drop-posthog-middleware-fix

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9426a7e and 1f92187.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • src/backend/conversations/settings.py (1 hunks)
  • src/backend/core/posthog.py (0 hunks)
💤 Files with no reviewable changes (1)
  • src/backend/core/posthog.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test-e2e-chromium
  • GitHub Check: test-back
  • GitHub Check: build-and-push-frontend
  • GitHub Check: build-and-push-backend
🔇 Additional comments (2)
CHANGELOG.md (1)

17-20: LGTM!

The changelog entry is properly formatted and accurately documents the removal of the custom PostHog async middleware, with appropriate PR reference.

src/backend/conversations/settings.py (1)

315-315: Tests appear to be missing from this PR despite objectives stating they should be preserved.

The middleware change is compatible—the standard posthog.integrations.django.PosthogContextMiddleware does support the existing configuration methods POSTHOG_MW_REQUEST_FILTER and POSTHOG_MW_EXTRA_TAGS as standard Django settings. Your implementation correctly follows the expected pattern (returning a boolean filter and a dict of tags).

However, no PostHog middleware tests were found in the codebase. The PR objectives mention "Preserve the test added in the reverted commit," but these tests do not appear to have been preserved. Please confirm whether tests should be included in this PR and add them if required.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Posthog fixed their middleware in v6.7.14
This reverts commit fbe9e03.
@qbey qbey force-pushed the qbey/drop-posthog-middleware-fix branch from ad0a8a8 to 1f92187 Compare November 5, 2025 23:03
@qbey qbey merged commit 1f92187 into main Nov 5, 2025
19 checks passed
@qbey qbey deleted the qbey/drop-posthog-middleware-fix branch November 5, 2025 23:08
qbey added a commit that referenced this pull request Nov 10, 2025
Fixed

- 🦺(front) Fix send prohibited file types
- 🐛(front) fix target blank links in chat #103
- 🚑️(posthog) pass str instead of UUID for user PK #134
- ⚡️(web-search) keep running when tool call fails #137
- ✨(summarize): new summarize tool integration #78

Removed

- 🔥(posthog) remove posthog middleware for async mode fix #146
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants