: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): preserve markdown migration history author (#67137)
Marius Andrab2d9d589dd9d
diff --git a/products/notebooks/backend/markdown_migration.py b/products/notebooks/backend/markdown_migration.pyindex 670b3fca68de..7a6151016c8e 100644--- a/products/notebooks/backend/markdown_migration.py+++ b/products/notebooks/backend/markdown_migration.py@@ -1,4 +1,5 @@from collections.abc import Callable+from datetime import timedeltafrom typing import Any, castfrom django.db import transaction@@ -139,7 +140,7 @@ def _convert_notebook(notebook: Notebook, *, user: User, content: dict[str, Any]if is_markdown_notebook_content(locked_notebook.content):return False- before_update = Notebook.objects.get(pk=locked_notebook.pk)+ before_update = Notebook.objects.select_related("created_by", "last_modified_by").get(pk=locked_notebook.pk)annotated_content = annotate_python_nodes(content)locked_notebook.content = annotated_contentlocked_notebook.text_content = text_content@@ -170,10 +171,10 @@ def _convert_notebook(notebook: Notebook, *, user: User, content: dict[str, Any]notebook=locked_notebook,organization_id=cast(UUIDT, locked_notebook.team.organization_id),team_id=locked_notebook.team_id,- user=user,+ user=before_update.last_modified_by or before_update.created_by or user,was_impersonated=False,changes=changes,- created_at=before_update.last_modified_at,+ created_at=before_update.last_modified_at + timedelta(seconds=1),)return Truediff --git a/products/notebooks/backend/test/test_markdown_migration.py b/products/notebooks/backend/test/test_markdown_migration.pyindex fe00267d8a64..a10a4f10a80f 100644--- a/products/notebooks/backend/test/test_markdown_migration.py+++ b/products/notebooks/backend/test/test_markdown_migration.py@@ -328,7 +328,9 @@ class TestNotebookMarkdownMigration(BaseTest):assert changes_by_field["version"]["after"] == 8assert "last_modified_at" not in changes_by_fieldassert "last_modified_by" not in changes_by_field- assert log.created_at == original_modified_at+ assert log.user_id == original_modifier.id+ assert log.user_id != self.user.id+ assert log.created_at == original_modified_at + timedelta(seconds=1)mock_publish.assert_called_once_with(self.team.id, notebook.short_id, 8, diff=None)def test_apply_scopes_mention_label_lookup_to_notebook_organization(self) -> None: