:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(notebooks): keep migrated filters closed (#67335)
Marius Andra922abe4fa12e
diff --git a/frontend/src/scenes/notebooks/Notebook/markdownNotebookDowngrade.test.ts b/frontend/src/scenes/notebooks/Notebook/markdownNotebookDowngrade.test.tsindex 0b6ba2d5e3c2..5d034e792b4c 100644--- a/frontend/src/scenes/notebooks/Notebook/markdownNotebookDowngrade.test.ts+++ b/frontend/src/scenes/notebooks/Notebook/markdownNotebookDowngrade.test.ts@@ -330,7 +330,7 @@ describe('markdownNotebookDowngrade', () => {it('converts component tags to their v1 node type with props as attrs', () => {expect(convertMarkdownToNotebookContent('<Query query={{"kind":"DataTableNode"}} />')).toEqual({type: 'doc',- content: [{ type: NotebookNodeType.Query, attrs: { query: { kind: 'DataTableNode' } } }],+ content: [{ type: NotebookNodeType.Query, attrs: { query: { kind: 'DataTableNode' }, edit: true } }],})})diff --git a/frontend/src/scenes/notebooks/Notebook/markdownNotebookDowngrade.ts b/frontend/src/scenes/notebooks/Notebook/markdownNotebookDowngrade.tsindex 02289a6f27e8..a4a304afa77c 100644--- a/frontend/src/scenes/notebooks/Notebook/markdownNotebookDowngrade.ts+++ b/frontend/src/scenes/notebooks/Notebook/markdownNotebookDowngrade.ts@@ -123,7 +123,7 @@ function convertComponentNode(node: NotebookComponentBlockNode): JSONContent | nconst notebookNodeType = MARKDOWN_TAG_TO_NOTEBOOK_NODE_TYPE[node.tagName]if (notebookNodeType) {- return { type: notebookNodeType, attrs: { ...node.props } }+ return { type: notebookNodeType, attrs: getNotebookNodeAttrsForMarkdownComponent(node) }}// No v1 node type for this tag — keep the serialized tag source as paragraph text so the@@ -131,6 +131,13 @@ function convertComponentNode(node: NotebookComponentBlockNode): JSONContent | nreturn makeParagraph(makeTextWithHardBreaks(serializeNode(node)))}+function getNotebookNodeAttrsForMarkdownComponent(node: NotebookComponentBlockNode): JSONContent['attrs'] {+ if (typeof node.props.hideFilters === 'boolean' || typeof node.props.edit === 'boolean') {+ return { ...node.props }+ }+ return { ...node.props, edit: true }+}+function convertListNode(node: NotebookListBlockNode): JSONContent[] {// Inverse of `serializeList` in markdownNotebookV2.ts: items with greater depth nest into the// previous shallower item's listItem as a child list. taskList and bulletList items cannotdiff --git a/frontend/src/scenes/notebooks/Notebook/markdownNotebookV2.test.ts b/frontend/src/scenes/notebooks/Notebook/markdownNotebookV2.test.tsindex 25172ac3c9ca..b49a54159bbb 100644--- a/frontend/src/scenes/notebooks/Notebook/markdownNotebookV2.test.ts+++ b/frontend/src/scenes/notebooks/Notebook/markdownNotebookV2.test.ts@@ -86,6 +86,13 @@ describe('markdownNotebookV2', () => {},},},+ {+ type: NotebookNodeType.Recording,+ attrs: {+ id: '018b4205-f670-7fa8-928a-040abaaf596d',+ title: 'Session replay',+ },+ },{type: NotebookNodeType.Image,attrs: {@@ -100,11 +107,35 @@ describe('markdownNotebookV2', () => {A **bold** paragraph.-<Query query={{"kind":"InsightVizNode","source":{"kind":"FunnelsQuery","series":[]}}} />+<Query hideFilters query={{"kind":"InsightVizNode","source":{"kind":"FunnelsQuery","series":[]}}} />++<Recording hideFilters id="018b4205-f670-7fa8-928a-040abaaf596d" title="Session replay" />`)})+ it('preserves explicitly open legacy widget filters', () => {+ const content: JSONContent = {+ type: 'doc',+ content: [+ {+ type: NotebookNodeType.Query,+ attrs: {+ query: {+ kind: 'SavedInsightNode',+ shortId: 'open',+ },+ edit: true,+ },+ },+ ],+ }++ expect(convertNotebookContentToMarkdown(content)).toEqual(+ '<Query query={{"kind":"SavedInsightNode","shortId":"open"}} />'+ )+ })+it('converts raw legacy content arrays without dropping top-level text nodes', () => {const content: JSONContent[] = [{@@ -152,9 +183,9 @@ Wrapped paragraph`)}expect(convertNotebookContentToMarkdown(content))- .toEqual(`<Query query={{"kind":"SavedInsightNode","shortId":"abc123"}} />+ .toEqual(`<Query hideFilters query={{"kind":"SavedInsightNode","shortId":"abc123"}} />-<Query query={{"kind":"SavedInsightNode","shortId":"def456"}} />`)+<Query hideFilters query={{"kind":"SavedInsightNode","shortId":"def456"}} />`)})it('converts remaining legacy production node shapes without unknown nodes', () => {@@ -179,7 +210,7 @@ Wrapped paragraph`)Dashboard 123-<Query query={{"kind":"DataVisualizationNode","source":{"kind":"HogQLQuery","query":"select event from events limit 1"}}} />`)+<Query hideFilters query={{"kind":"DataVisualizationNode","source":{"kind":"HogQLQuery","query":"select event from events limit 1"}}} />`)})it('keeps the stable id vector for markdown query blocks without nodeId props', () => {@@ -213,7 +244,7 @@ Dashboard 123// Nested undefined must be stripped, not cause the whole query prop to be dropped.expect(convertNotebookContentToMarkdown(content)).toEqual(- '<Query query={{"kind":"InsightVizNode","source":{"kind":"TrendsQuery","series":[{"kind":"EventsNode","event":"$pageview"}]}}} isDefaultFilterApplied={false} />'+ '<Query hideFilters query={{"kind":"InsightVizNode","source":{"kind":"TrendsQuery","series":[{"kind":"EventsNode","event":"$pageview"}]}}} isDefaultFilterApplied={false} />')})diff --git a/frontend/src/scenes/notebooks/Notebook/markdownNotebookV2.ts b/frontend/src/scenes/notebooks/Notebook/markdownNotebookV2.tsindex 838364f40376..88858eb7d63b 100644--- a/frontend/src/scenes/notebooks/Notebook/markdownNotebookV2.ts+++ b/frontend/src/scenes/notebooks/Notebook/markdownNotebookV2.ts@@ -486,7 +486,7 @@ function serializeRichContentNode(id: '',type: 'component',tagName: markdownTagName,- props: getSerializableAttrs(node.attrs),+ props: withDefaultHiddenFilters(getSerializableAttrs(node.attrs)),})}@@ -516,9 +516,9 @@ function serializeLegacyInsightNode(node: JSONContent): string {id: '',type: 'component',tagName: 'Query',- props: {+ props: withDefaultHiddenFilters({query: { kind: NodeKind.SavedInsightNode, shortId: insightShortId },- },+ }),})}@@ -542,7 +542,7 @@ function serializeLegacyQueryNode(node: JSONContent): string {id: '',type: 'component',tagName: 'Query',- props,+ props: withDefaultHiddenFilters(props),})}@@ -805,6 +805,13 @@ function getSerializableAttrs(attrs: Record<string, unknown> | undefined): Noteb}, {})}+function withDefaultHiddenFilters(props: NotebookComponentProps): NotebookComponentProps {+ if (typeof props.hideFilters === 'boolean' || typeof props.edit === 'boolean') {+ return props+ }+ return { ...props, hideFilters: true }+}+// Widget node attributes round-trip through HTML as JSON strings (NodeWrapper's jsonAttr), so a// persisted v1 node can carry an attr like `query` as the JSON *string* `'{"kind":...}'` rather than// the object. Serializing that string verbatim emits `query="..."`, which parses back as a string anddiff --git a/frontend/src/scenes/notebooks/Notebook/notebookUpgradeDialog.test.tsx b/frontend/src/scenes/notebooks/Notebook/notebookUpgradeDialog.test.tsxindex a1a4942976f4..3d7db37e632c 100644--- a/frontend/src/scenes/notebooks/Notebook/notebookUpgradeDialog.test.tsx+++ b/frontend/src/scenes/notebooks/Notebook/notebookUpgradeDialog.test.tsx@@ -66,7 +66,7 @@ describe('notebookUpgradeDialog', () => {expect(isMarkdownNotebookContent(convertedContent)).toBe(true)expect(getMarkdownNotebookMarkdown(convertedContent)).toEqual(`# Activation-<Query query={{"kind":"InsightVizNode","source":{"kind":"TrendsQuery","series":[]}}} />`)+<Query hideFilters query={{"kind":"InsightVizNode","source":{"kind":"TrendsQuery","series":[]}}} />`)})it('embeds comment threads from range-anchored comments during conversion', () => {diff --git a/products/notebooks/backend/markdown_conversion.py b/products/notebooks/backend/markdown_conversion.pyindex a841247564b4..f6b502654672 100644--- a/products/notebooks/backend/markdown_conversion.py+++ b/products/notebooks/backend/markdown_conversion.py@@ -287,7 +287,9 @@ def _serialize_rich_content_node(if isinstance(node_type, str) and node_type in NOTEBOOK_NODE_TYPE_TO_MARKDOWN_TAG:return _serialize_component_node(NOTEBOOK_NODE_TYPE_TO_MARKDOWN_TAG[node_type],- _get_serializable_attrs(node.get("attrs") if isinstance(node.get("attrs"), dict) else None),+ _with_default_hidden_filters(+ _get_serializable_attrs(node.get("attrs") if isinstance(node.get("attrs"), dict) else None)+ ),)child_markdown = "\n\n".join(@@ -314,7 +316,10 @@ def _serialize_legacy_insight_node(node: JSONContent) -> str:insight_short_id = attrs.get("short_id") if isinstance(attrs.get("short_id"), str) else attrs.get("id")if not isinstance(insight_short_id, str) or not insight_short_id:return _serialize_unknown_rich_content_node(node)- return _serialize_component_node("Query", {"query": {"kind": "SavedInsightNode", "shortId": insight_short_id}})+ return _serialize_component_node(+ "Query",+ _with_default_hidden_filters({"query": {"kind": "SavedInsightNode", "shortId": insight_short_id}}),+ )def _serialize_legacy_dashboard_node(node: JSONContent) -> str:@@ -330,7 +335,7 @@ def _serialize_legacy_query_node(node: JSONContent) -> str:query = props.get("query")if isinstance(query, dict) and query.get("kind") == "HogQLQuery":props["query"] = {"kind": "DataVisualizationNode", "source": query}- return _serialize_component_node("Query", props)+ return _serialize_component_node("Query", _with_default_hidden_filters(props))def _serialize_legacy_link_node(node: JSONContent, options: NotebookMarkdownConversionOptions) -> str:@@ -628,6 +633,12 @@ def _get_serializable_component_props(props: Mapping[str, NotebookPropValue]) ->return next_props+def _with_default_hidden_filters(props: dict[str, NotebookPropValue]) -> dict[str, NotebookPropValue]:+ if isinstance(props.get("hideFilters"), bool) or isinstance(props.get("edit"), bool):+ return props+ return {**props, "hideFilters": True}++def _get_ordered_component_prop_entries(props: Mapping[str, NotebookPropValue]) -> list[tuple[str, NotebookPropValue]]:entries = list(props.items())ordered_keys = ["hideFilters", "hideResults"]diff --git a/products/notebooks/backend/test/test_markdown_migration.py b/products/notebooks/backend/test/test_markdown_migration.pyindex a10a4f10a80f..a96c7770f986 100644--- a/products/notebooks/backend/test/test_markdown_migration.py+++ b/products/notebooks/backend/test/test_markdown_migration.py@@ -93,6 +93,50 @@ class TestNotebookMarkdownConversion(BaseTest):assert "juheapi" not in markdownassert "hideFilters" in markdown+ def test_converts_v1_widget_nodes_with_filters_closed_by_default(self) -> None:+ content = {+ "type": "doc",+ "content": [+ {+ "type": "ph-query",+ "attrs": {+ "query": {"kind": "SavedInsightNode", "shortId": "ZcWG6625"},+ "title": "Activation",+ },+ },+ {+ "type": "ph-recording",+ "attrs": {+ "id": "018b4205-f670-7fa8-928a-040abaaf596d",+ "title": "Session replay",+ },+ },+ {+ "type": "ph-insight",+ "attrs": {+ "id": "legacyInsight",+ },+ },+ {+ "type": "ph-query",+ "attrs": {+ "query": {"kind": "SavedInsightNode", "shortId": "open"},+ "edit": True,+ },+ },+ ],+ }++ markdown = convert_notebook_content_to_markdown(content)++ assert (+ '<Query hideFilters query={{"kind":"SavedInsightNode","shortId":"ZcWG6625"}} title="Activation" />'+ in markdown+ )+ assert '<Recording hideFilters id="018b4205-f670-7fa8-928a-040abaaf596d" title="Session replay" />' in markdown+ assert '<Query hideFilters query={{"kind":"SavedInsightNode","shortId":"legacyInsight"}} />' in markdown+ assert '<Query query={{"kind":"SavedInsightNode","shortId":"open"}} />' in markdown+def test_converts_legacy_markdown_ast_alias_nodes_without_losing_structure(self) -> None:content = {"type": "doc",