Skip to content

Commit

Permalink
fix(propdefs): Handle unresolvable group-type indexes properly (#25315)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverb123 authored Oct 1, 2024
1 parent cd2bed0 commit 9efa2a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 0 additions & 6 deletions rust/property-defs-rs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ pub struct Config {
#[envconfig(default = "1000000")]
pub cache_capacity: usize,

// We expire cache entries after this many seconds. This is /mostly/ to handle
// cases where we don't handle an insert error properly, so that a subsequent
// event seen can re-try the insert.
#[envconfig(default = "600")] // 10 minutes
pub cache_ttl_seconds: u64,

// We impose a slow-start, where each batch update operation is delayed by
// this many milliseconds, multiplied by the % of the cache currently unused. The idea
// is that we want to drip-feed updates to the DB during warmup, since
Expand Down
10 changes: 9 additions & 1 deletion rust/property-defs-rs/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ impl PropertyDefinition {
Some(GroupType::Resolved(_, i)) => Some(*i as i16),
Some(GroupType::Unresolved(group_name)) => {
warn!(
"Group type {} not resolved for property definition {} for team {}, skipping",
"Group type {} not resolved for property definition {} for team {}, skipping update",
group_name, self.name, self.team_id
);
None
Expand All @@ -452,6 +452,14 @@ impl PropertyDefinition {
}
};

if group_type_index.is_none() && matches!(self.event_type, PropertyParentType::Group) {
// Some teams/users wildly misuse group-types, and if we fail to issue an update
// during the transaction (which we do if we don't have a group-type index for a
// group property), the entire transaction is aborted, so instead we just warn
// loudly about this (above, and at resolve time), and drop the update.
return Ok(());
}

sqlx::query!(
r#"
INSERT INTO posthog_propertydefinition (id, name, type, group_type_index, is_numerical, volume_30_day, query_usage_30_day, team_id, property_type)
Expand Down

0 comments on commit 9efa2a0

Please sign in to comment.