Skip to content

fix(sql-editor): prevent Y-axis settings from being shared between series - #55753

Merged
thmsobrmlr merged 3 commits into
PostHog:masterfrom
okxint:fix/sql-y-axis-settings-copy-bug
Jun 16, 2026
Merged

thmsobrmlr merged 3 commits into
PostHog:masterfrom
okxint:fix/sql-y-axis-settings-copy-bug

Conversation

@okxint

@okxint okxint commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes #30932

When multiple Y-axes are configured in SQL insights, editing one series' visualization settings (display name, color, etc.) intermittently copies those settings to the previous series.

Changes

The root cause is shared object references between Y-axis settings entries. Settings objects flow through a round-trip cycle: selectedYAxis reducer -> axesChanged listener -> setQuery -> parent component -> _setQuery -> selectedYAxis reducer. Throughout this cycle, settings were passed by reference rather than being cloned, so multiple Y-axis entries could end up sharing the same settings object.

Added a cloneSettings helper (using lodash.merge deep copy) and applied it at all boundary points:

  • Initial state construction for selectedYAxis
  • _setQuery handlers for both selectedYAxis and tabularColumnSettings
  • axesChanged listener when writing settings to the query

This ensures each Y-axis entry always has an independent settings copy.

How did you test this code?

Agent-authored PR. The code formatting has been verified via pnpm --filter=@posthog/frontend format. CI will run the existing test suites.

Publish to changelog?

no

Docs update

not needed

LLM context

Agent-authored PR. The fix builds on top of the mutation fix in #53055, which addressed the lodash.merge target mutation but did not prevent shared references between series entries across the query round-trip.

…ries

When multiple Y-axes are configured in SQL insights, editing one series'
visualization settings (label, color, etc.) could intermittently copy
those settings to another series. This happened because settings objects
were passed by reference through the query round-trip cycle
(reducer -> axesChanged -> setQuery -> _setQuery -> reducer), allowing
multiple Y-axis entries to share the same settings object reference.

Deep clone settings at all boundary points where they enter or leave
the reducer state to ensure each Y-axis always has an independent copy.

Closes PostHog#30932
@greptile-apps

greptile-apps Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
This is a comment left during a code review.
Path: frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.ts
Line: 551-563

Comment:
**Repeated ternary pattern (OnceAndOnlyOnce)**

The expression `settings ? cloneSettings(settings) : DefaultAxisSettings()` is duplicated three times across the initial state and the two `_setQuery` handlers. Folding both helpers into one would remove the repetition:

```typescript
const cloneOrDefaultSettings = (settings?: AxisSeriesSettings): AxisSeriesSettings =>
    settings ? cloneSettings(settings) : DefaultAxisSettings()
```

Then each call site becomes the single, obvious `cloneOrDefaultSettings(axis.settings)` / `cloneOrDefaultSettings(column.settings)`.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(sql-editor): prevent Y-axis settings..." | Re-trigger Greptile

@github-actions

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the stale label – otherwise this will be closed in another week. If you want to permanently keep it open, use the waiting label.

@github-actions github-actions Bot added the stale label Apr 30, 2026
@okxint

okxint commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

Still relevant - this fixes a real bug where Y-axis settings are shared by reference between series in SQL insights. Happy to rebase if needed.

… duplication

Removes repeated `settings ? cloneSettings(settings) : DefaultAxisSettings()` ternary across Y-axis and tabular column handlers by introducing a single helper.
@greptile-apps

greptile-apps Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "refactor(sql-editor): extract cloneOrDef..." | Re-trigger Greptile

@okxint

okxint commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on current master. This fix is still needed — the bug (Y-axis settings being shared by reference between series) is reproducible in the current codebase.

@okxint

okxint commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

Still valid and relevant — happy to rebase on latest master if needed.

@okxint

okxint commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Still relevant — bumping to prevent auto-close.

@darkopia
darkopia requested a review from a team June 5, 2026 23:19
@okxint

okxint commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Gentle ping on this one — it's been open ~47 days. Happy to address any feedback or rebase if needed!

@thmsobrmlr
thmsobrmlr enabled auto-merge (squash) June 16, 2026 09:07

/** Deep clone settings to prevent shared references between Y-axis entries */
const cloneSettings = (settings: AxisSeriesSettings): AxisSeriesSettings =>
mergeObject({}, settings) as AxisSeriesSettings

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Seems we are already using lodash.mergeObject here, but structuredClone would probably be the more idiomatic way in this codebase.

@thmsobrmlr
thmsobrmlr merged commit c0398ab into PostHog:master Jun 16, 2026
173 checks passed
@deployment-status-posthog

deployment-status-posthog Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-06-16 11:42 UTC Run
prod-us ✅ Deployed 2026-06-16 11:55 UTC Run
prod-eu ✅ Deployed 2026-06-16 11:56 UTC Run

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.

Bug: SQL insights visualization customization copies current Y-axis settings to previous item

2 participants