Skip to content

Commit

Permalink
chore: alter column type (#26272)
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin authored Nov 20, 2024
1 parent af4801a commit a9865ef
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
17 changes: 17 additions & 0 deletions posthog/migrations/0521_alter_errortrackingstackframe_context.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
2 changes: 1 addition & 1 deletion posthog/migrations/max_migration.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0520_experiment_metrics_secondary
0521_alter_errortrackingstackframe_context
2 changes: 1 addition & 1 deletion posthog/models/error_tracking/error_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions rust/cymbal/src/frames/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand All @@ -66,7 +66,7 @@ impl ErrorTrackingStackFrame {
serde_json::to_value(&self.contents)?,
self.resolved,
Uuid::now_v7(),
context
context,
).execute(e).await?;
Ok(())
}
Expand All @@ -86,7 +86,7 @@ impl ErrorTrackingStackFrame {
symbol_set_id: Option<Uuid>,
contents: Value,
resolved: bool,
context: Option<String>,
context: Option<Value>,
}
let res = sqlx::query_as!(
Returned,
Expand All @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

Expand Down

0 comments on commit a9865ef

Please sign in to comment.