Skip to content

Fix/prisma length mismatch#4268

Open
KAUSHALCODER123 wants to merge 3 commits into
umami-software:masterfrom
KAUSHALCODER123:fix/prisma-length-mismatch
Open

Fix/prisma length mismatch#4268
KAUSHALCODER123 wants to merge 3 commits into
umami-software:masterfrom
KAUSHALCODER123:fix/prisma-length-mismatch

Conversation

@KAUSHALCODER123
Copy link
Copy Markdown

Changes Made
Branch: fix/prisma-length-mismatch
Commit: fix: truncate tracking data to prevent Prisma length mismatch errors (P2000)
Summary:
Added length constants to src/lib/constants.ts based on the PostgreSQL schema (UTM params, click IDs, tags, hostnames, etc.).
Applied .substring() truncation to all relevant fields in saveEvent.ts, saveEventData.ts, saveSessionData.ts, and createSession.ts.
This ensures that any excessively long strings sent to the tracking API (e.g., from long UTM parameters) are safely truncated before reaching the database, preventing the P2000 error.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

@KAUSHALCODER123 is attempting to deploy a commit to the Umami Software Team on Vercel.

A member of the Team first needs to authorize it.

@KAUSHALCODER123
Copy link
Copy Markdown
Author

please accept my pull request

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 10, 2026

Greptile Summary

This PR adds length-capped .substring() truncation to all tracked string fields before they reach the database, preventing Prisma P2000 errors from over-length inputs. It also bundles an unrelated rrweb upgrade (alpha.4 → alpha.20) and a new opt-in console-log recording feature for session replays.

  • Truncation fix: New constants in constants.ts match the Prisma schema exactly; saveEvent.ts, createSession.ts, and saveSessionData.ts are consistently updated across both relational and ClickHouse paths.
  • Gap: saveEventData.ts updates only the relational path — its ClickHouse query still passes data_key and string_value without truncation, unlike the equivalent path in saveSessionData.ts.
  • Scope: The rrweb major version bump (16 alpha releases) and console recording UI are unrelated to the stated fix and should be reviewed separately.

Confidence Score: 3/5

The truncation fix is correct where applied but has a gap in the ClickHouse event-data path; the rrweb library jump across 16 alpha releases is a substantial unreviewed change bundled into this PR.

The Prisma truncation logic is solid — all constants match the schema and the affected files are consistently updated — except saveEventData.ts whose ClickHouse path was overlooked, leaving it without truncation while the parallel saveSessionData.ts ClickHouse path was fixed. The bigger concern is the unrelated rrweb upgrade from alpha.4 to alpha.20 plus two new packages: this is a large cross-cutting change with no test coverage visible in the diff, and any regression in the replay recorder or player would be hard to attribute without a separate PR.

src/queries/sql/events/saveEventData.ts (ClickHouse path gap) and package.json / pnpm-lock.yaml (unreviewed rrweb major bump)

Important Files Changed

Filename Overview
src/lib/constants.ts Adds 11 length constants that correctly match the PostgreSQL/Prisma schema column sizes.
src/queries/sql/events/saveEvent.ts Applies .substring() truncation to all event fields (UTM params, click IDs, tag, hostname, currency) in both relational and ClickHouse paths.
src/queries/sql/events/saveEventData.ts Relational path correctly adds truncation, but the ClickHouse path still writes data_key and string_value without truncation — inconsistent with saveSessionData.ts which fixed both paths.
src/queries/sql/sessions/createSession.ts Correctly truncates all session fields before the raw SQL insert; constants match the Prisma schema exactly.
src/queries/sql/sessions/saveSessionData.ts Both relational and ClickHouse paths receive truncation for data_key and string_value.
package.json Upgrades rrweb from alpha.4 to alpha.20 (16 alpha releases) and adds two new console plugin packages — a large unrelated change bundled with the Prisma truncation fix.
src/recorder/index.js Adds opt-in console recording via data-record-console attribute, cleanly integrated into the existing plugin array pattern.
src/app/(main)/websites/[websiteId]/settings/WebsiteReplaySettings.tsx Adds a recordConsole boolean to the replay config and surfaces it as a Switch in the settings UI.
src/app/(main)/websites/[websiteId]/replays/[replayId]/ReplayPlayer.tsx Loads the rrweb console replay plugin alongside rrweb-player and passes it via the plugins array.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Incoming Tracking Request] --> B{Route}
    B --> C[saveEvent]
    B --> D[saveEventData]
    B --> E[createSession]
    B --> F[saveSessionData]

    C --> C1[Relational: truncate UTM, clickIDs, tag, hostname, currency ✅]
    C --> C2[ClickHouse: truncate UTM, clickIDs, tag, hostname ✅]

    D --> D1[Relational: truncate dataKey, stringValue ✅]
    D --> D2[ClickHouse: NO truncation ❌]

    E --> E1[Relational: truncate browser, os, device, screen, language, country, region, city, distinctId ✅]

    F --> F1[Relational: truncate dataKey, stringValue ✅]
    F --> F2[ClickHouse: truncate dataKey, stringValue ✅]

    style D2 fill:#ff6666,color:#fff
Loading

Comments Outside Diff (1)

  1. src/queries/sql/events/saveEventData.ts, line 65-67 (link)

    P1 ClickHouse path missing truncation for event data

    The ClickHouse path in this file still writes data_key and string_value without truncation, while the relational path (just above) was updated and the equivalent ClickHouse path in saveSessionData.ts was also updated. Any ClickHouse column with a fixed String size limit would receive over-length values from event data submissions, behaving inconsistently with the session-data path that was corrected in this same PR.

Reviews (1): Last reviewed commit: "fix: truncate tracking data to prevent P..." | Re-trigger Greptile

Comment thread package.json
Comment on lines 108 to +111
"react-window": "^1.8.6",
"redis": "^4.5.1",
"request-ip": "^3.3.0",
"rrweb": "2.0.0-alpha.4",
"rrweb-player": "1.0.0-alpha.4",
"rrweb": "2.0.0-alpha.20",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Unrelated major rrweb version bump bundled with truncation fix

This PR upgrades rrweb from 2.0.0-alpha.4 to 2.0.0-alpha.20 and adds two new packages (@rrweb/rrweb-plugin-console-record, @rrweb/rrweb-plugin-console-replay), which is a substantial jump across 16 alpha releases. Because these changes are bundled with the unrelated Prisma truncation fix, a regression in the replay player or the recorder would be hard to bisect. The console recording feature also alters what data is captured and stored per session. This should be split into a separate PR so the rrweb upgrade can be reviewed and tested independently.

@KAUSHALCODER123
Copy link
Copy Markdown
Author

did again

@Xetera
Copy link
Copy Markdown

Xetera commented May 17, 2026

I think you need to remove the unrelated recording changes from this PR before it can be accepted

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.

2 participants