diff --git a/posthog/migrations/0521_alter_errortrackingstackframe_context.py b/posthog/migrations/0521_alter_errortrackingstackframe_context.py new file mode 100644 index 0000000000000..6034b72334a9a --- /dev/null +++ b/posthog/migrations/0521_alter_errortrackingstackframe_context.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.15 on 2024-11-19 10:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("posthog", "0520_experiment_metrics_secondary"), + ] + + operations = [ + migrations.AlterField( + model_name="errortrackingstackframe", + name="context", + field=models.JSONField(blank=True, null=True), + ), + ] diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txt index 31b8c212f629f..8d2eb0a249399 100644 --- a/posthog/migrations/max_migration.txt +++ b/posthog/migrations/max_migration.txt @@ -1 +1 @@ -0520_experiment_metrics_secondary +0521_alter_errortrackingstackframe_context diff --git a/posthog/models/error_tracking/error_tracking.py b/posthog/models/error_tracking/error_tracking.py index 7e42f55cf9f77..f2e3e2276658c 100644 --- a/posthog/models/error_tracking/error_tracking.py +++ b/posthog/models/error_tracking/error_tracking.py @@ -76,7 +76,7 @@ class ErrorTrackingStackFrame(UUIDModel): contents = models.JSONField(null=False, blank=False) resolved = models.BooleanField(null=False, blank=False) # The context around the frame, +/- a few lines, if we can get it - context = models.TextField(null=True, blank=True) + context = models.JSONField(null=True, blank=True) class Meta: indexes = [ diff --git a/rust/.sqlx/query-085d682315a548d578f63bb48d2f1997fc9cf1fb3436d742e9374ad4f2d55614.json b/rust/.sqlx/query-085d682315a548d578f63bb48d2f1997fc9cf1fb3436d742e9374ad4f2d55614.json index 9329bd2f2da48..50533517b912f 100644 --- a/rust/.sqlx/query-085d682315a548d578f63bb48d2f1997fc9cf1fb3436d742e9374ad4f2d55614.json +++ b/rust/.sqlx/query-085d682315a548d578f63bb48d2f1997fc9cf1fb3436d742e9374ad4f2d55614.json @@ -12,7 +12,7 @@ "Jsonb", "Bool", "Uuid", - "Text" + "Jsonb" ] }, "nullable": [] diff --git a/rust/.sqlx/query-4b24f800767bc20852115e7406f8dc46c18f4950a7951d2c412dcba4d13fb56b.json b/rust/.sqlx/query-4b24f800767bc20852115e7406f8dc46c18f4950a7951d2c412dcba4d13fb56b.json index 515f058fad974..e4d2abe66f917 100644 --- a/rust/.sqlx/query-4b24f800767bc20852115e7406f8dc46c18f4950a7951d2c412dcba4d13fb56b.json +++ b/rust/.sqlx/query-4b24f800767bc20852115e7406f8dc46c18f4950a7951d2c412dcba4d13fb56b.json @@ -36,7 +36,7 @@ { "ordinal": 6, "name": "context", - "type_info": "Text" + "type_info": "Jsonb" } ], "parameters": { diff --git a/rust/cymbal/src/frames/records.rs b/rust/cymbal/src/frames/records.rs index 8b969f060f7b9..ef17a0f991b04 100644 --- a/rust/cymbal/src/frames/records.rs +++ b/rust/cymbal/src/frames/records.rs @@ -44,7 +44,7 @@ impl ErrorTrackingStackFrame { E: Executor<'c, Database = sqlx::Postgres>, { let context = if let Some(context) = &self.context { - Some(serde_json::to_string(context)?) + Some(serde_json::to_value(context)?) } else { None }; @@ -66,7 +66,7 @@ impl ErrorTrackingStackFrame { serde_json::to_value(&self.contents)?, self.resolved, Uuid::now_v7(), - context + context, ).execute(e).await?; Ok(()) } @@ -86,7 +86,7 @@ impl ErrorTrackingStackFrame { symbol_set_id: Option, contents: Value, resolved: bool, - context: Option, + context: Option, } let res = sqlx::query_as!( Returned, @@ -109,10 +109,11 @@ impl ErrorTrackingStackFrame { // and so when we load a frame record we need to patch back up the context onto the frame, // since we dropped it when we serialised the frame during saving. let mut frame: Frame = serde_json::from_value(found.contents)?; - let context = if let Some(context) = found.context.as_ref() { + + let context = if let Some(context) = found.context { // We serialise the frame context as a json string, but it's a structure we have to manually // deserialise back into the frame. - Some(serde_json::from_str(context)?) + serde_json::from_value(context)? } else { None }; diff --git a/rust/cymbal/tests/test_migrations/20241101134611_test_migration_for_symbol_set_saving_tests.sql b/rust/cymbal/tests/test_migrations/20241101134611_test_migration_for_symbol_set_saving_tests.sql index 88029256999b0..b9b73d3a43de7 100644 --- a/rust/cymbal/tests/test_migrations/20241101134611_test_migration_for_symbol_set_saving_tests.sql +++ b/rust/cymbal/tests/test_migrations/20241101134611_test_migration_for_symbol_set_saving_tests.sql @@ -19,7 +19,7 @@ CREATE TABLE IF NOT EXISTS posthog_errortrackingstackframe ( symbol_set_id UUID, contents JSONB NOT NULL, resolved BOOLEAN NOT NULL, - context TEXT, + context JSONB, UNIQUE(raw_id, team_id) );