Skip to content

[CI] (9f92c68) fastapi/fastapi3-ai-saas - #2513

Closed
wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-9f92c68-fastapi-fastapi3-ai-saas
Closed

wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-9f92c68-fastapi-fastapi3-ai-saas

Conversation

@wizard-ci-bot

@wizard-ci-bot wizard-ci-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

Automated wizard CI run

Source: wizard-pr
Trigger ID: 9f92c68
App: fastapi/fastapi3-ai-saas
App directory: apps/fastapi/fastapi3-ai-saas
Workbench branch: wizard-ci-9f92c68-fastapi-fastapi3-ai-saas
Wizard branch: release-please--branches--main--components--wizard
Context Mill branch: main
PostHog (MCP) branch: master
Timestamp: 2026-07-08T16:48:35.818Z
Duration: 451.9s

YARA Scanner

✓ 57 tool calls scanned, 0 violations detected

No violations: ✓ 57 clean scans

@wizard-ci-bot

wizard-ci-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown
Author

Now I have all the context I need. The .env.example was NOT updated with PostHog variables. The User model uses id (int) as primary key and email as a separate field — so using user.email as the distinct_id instead of str(user.id) is a deliberate but problematic choice.


PR Evaluation Report

Summary

This PR integrates PostHog analytics into a FastAPI AI SaaS application. It adds PostHog initialization in the lifespan manager, creates a custom ASGI middleware for request-scoped contexts, and instruments 9 events across auth, content generation, API key management, and settings routes. The integration has two significant issues: it calls a non-existent posthog.identify() method (Python SDK has no identify()) and uses raw email addresses as distinct IDs throughout.

Files changed Lines added Lines removed
9 +174 -2

Confidence score: 4/5 👍

  • posthog.identify() does not exist in the Python SDK — The Python SDK has no identify() method. The two calls in auth.py (posthog.identify(user.email, {"is_active": user.is_active})) will raise AttributeError at runtime when users log in or sign up. Use posthog.set(distinct_id=str(user.id), properties={"is_active": user.is_active}) instead. [CRITICAL]
  • Email used as distinct_id everywhere — identify_context(user.email) and posthog.identify(user.email, ...) use raw email addresses as distinct IDs. This is a PII concern and causes fragmented data if a user changes their email. Use str(user.id) (the integer primary key) as the distinct_id. [CRITICAL]
  • .env.example not updated — The PR adds POSTHOG_PROJECT_TOKEN, POSTHOG_HOST, and POSTHOG_DISABLED settings via Pydantic but does not document them in .env.example, which collaborators rely on. [MEDIUM]

File changes

Filename Score Description
app/config.py 4/5 Adds PostHog settings fields to Pydantic Settings class with sensible defaults
app/main.py 4/5 Initializes PostHog in lifespan, registers middleware, flushes on shutdown
app/middleware.py 2/5 Custom ASGI middleware with PostHog context; uses email as distinct_id instead of user.id
app/routers/auth.py 2/5 Calls non-existent posthog.identify(), uses email as distinct_id
app/routers/generate.py 5/5 Well-structured capture calls with meaningful properties
app/routers/api_keys.py 4/5 Captures API key lifecycle events; events lack properties
app/routers/settings.py 4/5 Captures settings and password change events
requirements.txt 5/5 Adds posthog dependency
posthog-setup-report.md 4/5 Comprehensive setup report documenting all changes

App sanity check ⚠️

Criteria Result Description
App builds and runs Yes Python won't fail at import time; the posthog.identify() error only triggers at runtime on login/signup
Preserves existing env vars & configs Yes All existing code preserved; new settings added additively
No syntax or type errors No posthog.identify() does not exist in the Python SDK — this is a runtime AttributeError
Correct imports/exports Yes All imports resolve to valid posthog module-level functions
Minimal, focused changes Yes All changes are PostHog-related
Pre-existing issues None Base app is clean

Issues

  • posthog.identify() does not exist: The Python SDK has no identify() method. The two calls in auth.py will raise AttributeError at runtime during login and signup flows. Replace with posthog.set(distinct_id=str(user.id), properties={"is_active": user.is_active}). [CRITICAL]
  • .env.example not updated: New PostHog environment variables (POSTHOG_PROJECT_TOKEN, POSTHOG_HOST, POSTHOG_DISABLED) are not documented in .env.example. [MEDIUM]

Other completed criteria

  • App starts and initializes PostHog correctly in the lifespan context manager
  • Existing routers, models, and database initialization are fully preserved
  • PostHog middleware is registered cleanly via app.add_middleware()
  • posthog.flush() called on shutdown to ensure events are sent

PostHog implementation ⚠️

Criteria Result Description
PostHog SDKs installed Yes posthog>=3.0.0 added to requirements.txt
PostHog client initialized Yes Module-level posthog.api_key and posthog.host set in lifespan context manager, matching FastAPI pattern
capture() Yes 9 capture calls across auth, generate, api_keys, and settings routers
identify() N/A Server-only app
Error tracking Yes Middleware wraps all requests in new_context() which auto-captures exceptions by default
Reverse proxy N/A Server-only app

Issues

  • Non-existent posthog.identify() called: auth.py calls posthog.identify(user.email, {"is_active": user.is_active}) twice. The Python SDK does not have an identify() method — use posthog.set(distinct_id=str(user.id), properties={"is_active": user.is_active}) to set person properties. [CRITICAL]
  • Email as distinct_id: Both the middleware (identify_context(user.email)) and auth routes use user.email as the distinct_id. The User model has an integer id primary key which is a stable, non-PII identifier — use str(user.id) instead. [CRITICAL]

Other completed criteria

  • API key loaded from environment via Pydantic Settings (posthog_project_token maps to POSTHOG_PROJECT_TOKEN env var)
  • Host correctly configured to https://us.i.posthog.com
  • PostHog disabled flag allows disabling in tests/dev
  • Middleware correctly uses new_context() with identify_context() and tag() pattern

PostHog insights and events ⚠️

Filename PostHog events Description
app/routers/auth.py user_signed_up, user_logged_in, user_logged_out Auth lifecycle events; signup/login include method properties
app/routers/generate.py content_generated, insufficient_credits Content generation with type, credits_used, credits_remaining; insufficient credits with credits_needed/available
app/routers/api_keys.py api_key_created, api_key_revoked API key lifecycle events (no enriching properties)
app/routers/settings.py settings_updated, password_changed Account settings changes; settings_updated includes fields_changed

Issues

  • Email used as distinct_id is PII: Raw email addresses are used as distinct IDs via identify_context(user.email) throughout. This embeds PII into every event's distinct_id field. Use the user's integer primary key instead. [CRITICAL]
  • API key events lack properties: api_key_created and api_key_revoked have no properties — adding the key name or key ID would improve debuggability. [LOW]

Other completed criteria

  • Events represent real user actions mapped to actual product flows (signup → login → generate → manage keys)
  • Events enable product insights — can build signup-to-generation funnel, track credit depletion, monitor API key activity
  • Content generation events include rich properties (generation_type, credits_used, credits_remaining)
  • Event names follow consistent snake_case convention with descriptive verb-based naming

Reviewed by wizard workbench PR evaluator

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.

0 participants