Skip to content

: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.

fix(notebooks): allow saving blank titles (#59185)

Alex Lidera30a3d0619b1
diff --git a/products/notebooks/backend/api/notebook.py b/products/notebooks/backend/api/notebook.py
index 8ddb923b3f3a..b50665f12256 100644
--- a/products/notebooks/backend/api/notebook.py
+++ b/products/notebooks/backend/api/notebook.py
@@ -292,8 +292,11 @@ class NotebookCollabSaveSerializer(serializers.Serializer):
help_text="List of ProseMirror step JSON objects to apply.",
)
content = serializers.JSONField(help_text="The resulting ProseMirror document after applying the steps locally.")
- text_content = serializers.CharField(required=False, default="", help_text="Plain text for search indexing.")
- title = serializers.CharField(required=False, help_text="Updated notebook title.")
+ text_content = serializers.CharField(
+ required=False, allow_blank=True, default="", help_text="Plain text for search indexing."
+ )
+ # No default: omitted title should preserve the existing notebook title, while "" clears it.
+ title = serializers.CharField(required=False, allow_blank=True, help_text="Updated notebook title.")
cursor_head = serializers.IntegerField(
required=False, allow_null=True, help_text="ProseMirror cursor head position after applying steps."
)
diff --git a/products/notebooks/backend/test/test_collab_api.py b/products/notebooks/backend/test/test_collab_api.py
index 3308ea2b0a66..4cd39676ad42 100644
--- a/products/notebooks/backend/test/test_collab_api.py
+++ b/products/notebooks/backend/test/test_collab_api.py
@@ -28,7 +28,9 @@ class TestNotebookCollabSaveAPI(APIBaseTest):
assert response.status_code == status.HTTP_201_CREATED
return response.json()
- def _collab_save(self, notebook, *, version, steps, content=None, text_content=None, client_id="test-client"):
+ def _collab_save(
+ self, notebook, *, version, steps, content=None, text_content=None, title=None, client_id="test-client"
+ ):
payload = {
"client_id": client_id,
"version": version,
@@ -37,6 +39,8 @@ class TestNotebookCollabSaveAPI(APIBaseTest):
}
if text_content is not None:
payload["text_content"] = text_content
+ if title is not None:
+ payload["title"] = title
return self.client.post(
f"/api/projects/{self.team.id}/notebooks/{notebook['short_id']}/collab/save/",
data=payload,
@@ -101,6 +105,25 @@ class TestNotebookCollabSaveAPI(APIBaseTest):
nb = Notebook.objects.get(short_id=notebook["short_id"])
assert nb.title == "New Title"
+ def test_collab_save_allows_blank_title(self):
+ notebook = self._create_notebook(SAMPLE_DOC)
+ version = notebook["version"]
+
+ response = self._collab_save(
+ notebook,
+ version=version,
+ steps=[{"stepType": "replace", "from": 0, "to": 0}],
+ content={"type": "doc", "content": [{"type": "heading"}]},
+ text_content="",
+ title="",
+ )
+
+ assert response.status_code == status.HTTP_200_OK
+ assert response.json()["title"] == ""
+ nb = Notebook.objects.get(short_id=notebook["short_id"])
+ assert nb.title == ""
+ assert nb.text_content == ""
+
def test_collab_save_rejected_stale_version(self):
notebook = self._create_notebook(SAMPLE_DOC)
version = notebook["version"]
diff --git a/products/notebooks/backend/test/test_notebook_api_serializers.py b/products/notebooks/backend/test/test_notebook_api_serializers.py
new file mode 100644
index 000000000000..a097948d54fc
--- /dev/null
+++ b/products/notebooks/backend/test/test_notebook_api_serializers.py
@@ -0,0 +1,31 @@
+import pytest
+
+from products.notebooks.backend.api.notebook import NotebookCollabSaveSerializer
+
+
+ ("optional_payload", "expected_title"),
+ [
+ pytest.param({"text_content": "", "title": ""}, "", id="blank-title"),
+ pytest.param({"text_content": ""}, None, id="omitted-title"),
+ ],
+)
+def test_collab_save_serializer_handles_blank_and_omitted_title(
+ optional_payload: dict[str, object], expected_title: str | None
+) -> None:
+ serializer = NotebookCollabSaveSerializer(
+ data={
+ "client_id": "test-client",
+ "version": 0,
+ "steps": [{"stepType": "replace", "from": 0, "to": 0}],
+ "content": {"type": "doc", "content": [{"type": "heading"}]},
+ **optional_payload,
+ }
+ )
+
+ assert serializer.is_valid(), serializer.errors
+ assert serializer.validated_data["text_content"] == ""
+ if expected_title is None:
+ assert "title" not in serializer.validated_data
+ else:
+ assert serializer.validated_data["title"] == expected_title