Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(similarity): Add try catch around insert grouping record #1184

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jangjodi
Copy link
Member

@jangjodi jangjodi commented Sep 19, 2024

Add on_conflict_do_nothing for inserting group records

fixes SEER-9Y

@jangjodi jangjodi requested review from a team September 19, 2024 18:41
@@ -498,15 +504,26 @@ def insert_new_grouping_record(
error_type=issue.exception_type,
).to_db_model()
session.add(new_record)

try:
session.flush()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why flush?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially thought we didn't want to rollback the entire session, but that was incorrect. I created a new session to rollback, but would it also work if I kept the session parameter and did rollback since there were no other adds?

"input_hash": issue.hash,
}

if existing_record is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we modify this to return early if existing record is not none so we don't get so much arrowing? https://blog.codinghorror.com/flattening-arrow-code/

try:
session.commit()
except IntegrityError:
session.rollback()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does rollback do? do we need it here?

Comment on lines 510 to 519
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,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm wondering if this is necessary or if we can skip not having this log -- in theory we should be able to see the group hashes linked on the sentry side, right?

Copy link
Member

@JoshFerge JoshFerge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any way to add a test that enters this logic for this case?

@jangjodi
Copy link
Member Author

@JoshFerge I updated this PR to use on_conflict_do_nothing, instead of logging and doing the try catch. Let me know if that makes sense!

Copy link
Member

@JoshFerge JoshFerge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants