Skip to content

Commit

Permalink
chore(similarity): Add try catch around insert grouping record
Browse files Browse the repository at this point in the history
  • Loading branch information
jangjodi committed Sep 19, 2024
1 parent 0104de0 commit db3a02e
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/seer/grouping/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pydantic import BaseModel, ValidationInfo, field_validator
from sentence_transformers import SentenceTransformer
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.exc import IntegrityError
from torch.cuda import OutOfMemoryError

from seer.db import DbGroupingRecord, Session
Expand Down Expand Up @@ -477,7 +478,6 @@ def insert_new_grouping_record(
) -> None:
"""
Inserts a new GroupingRecord into the database if the group_hash does not already exist.
If new grouping record was created, return the id.
:param session: The database session.
:param issue: The issue to insert as a new GroupingRecord.
Expand All @@ -489,6 +489,12 @@ def insert_new_grouping_record(
.first()
)

extra = {
"project_id": issue.project_id,
"stacktrace_length": len(issue.stacktrace),
"input_hash": issue.hash,
}

if existing_record is None:
new_record = GroupingRecord(
project_id=issue.project_id,
Expand All @@ -498,15 +504,26 @@ def insert_new_grouping_record(
error_type=issue.exception_type,
).to_db_model()
session.add(new_record)

try:
session.flush()
except IntegrityError:
session.expunge(new_record)
existing_record = (
session.query(DbGroupingRecord)
.filter_by(hash=issue.hash, project_id=issue.project_id)
.first()
)
extra["existing_hash"] = existing_record.hash
logger.info(
"group_already_exists_in_seer_db",
extra=extra,
)
else:
extra["existing_hash"] = existing_record.hash
logger.info(
"group_already_exists_in_seer_db",
extra={
"existing_hash": existing_record.hash,
"project_id": issue.project_id,
"stacktrace_length": len(issue.stacktrace),
"input_hash": issue.hash,
},
extra=extra,
)

@sentry_sdk.tracing.trace
Expand Down

0 comments on commit db3a02e

Please sign in to comment.