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

fix: use get_or_create in CommitSerializer.create #437

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

joseph-sentry
Copy link
Contributor

Purpose/Motivation

there is a possibility of creating commits concurrently if that happens there is a possibility of getting an IntegrityError when trying to create the Commit object

this commit solves this problem by using get_or_create to create the Commit object in the serializer

What does this PR do?

  • remove repository and commitid from validated data so its not included in the defaults
  • use get_or_create instead of filter then super().create

@joseph-sentry joseph-sentry requested a review from a team as a code owner March 6, 2024 15:35
@codecov-staging
Copy link

codecov-staging bot commented Mar 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link

codecov-public-qa bot commented Mar 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@7932e93). Click here to learn what that means.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #437   +/-   ##
=======================================
  Coverage        ?   96.05%           
=======================================
  Files           ?      643           
  Lines           ?    17060           
  Branches        ?        0           
=======================================
  Hits            ?    16387           
  Misses          ?      673           
  Partials        ?        0           
Flag Coverage Δ
unit 96.05% <100.00%> (?)
unit-latest-uploader 96.05% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
upload/serializers.py 100.00% <100.00%> (ø)

Impacted file tree graph

Copy link
Contributor

@giovanni-guidini giovanni-guidini left a comment

Choose a reason for hiding this comment

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

I was looking at mentions of CommitSerializer in the unit tests, but could only find tests in which the create method are not called.

In tests/views/test_commits.py::test_create_commit_already_exists I don't see an assert to make sure that a duplicated Commit was not created.

Can you add a test that calls the CommitSerializer.create method twice and/or asserts that no duplicates happen?

if commit:
return commit
return super().create(validated_data)
repo = validated_data.pop("repository", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this is a Repository and not RepositorySerializer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because we pass repository to the serializer.save call here which will then get put into the dict that is passed to this create here

Copy link
Contributor

Choose a reason for hiding this comment

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

perfection, thank you for checking that

@codecov-qa
Copy link

codecov-qa bot commented Mar 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@7932e93). Click here to learn what that means.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #437   +/-   ##
=======================================
  Coverage        ?   96.05%           
=======================================
  Files           ?      643           
  Lines           ?    17060           
  Branches        ?        0           
=======================================
  Hits            ?    16387           
  Misses          ?      673           
  Partials        ?        0           
Flag Coverage Δ
unit 96.05% <100.00%> (?)
unit-latest-uploader 96.05% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

if commit:
return commit
return super().create(validated_data)
repo = validated_data.pop("repository", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

perfection, thank you for checking that

there is a possibility of creating commits concurrently
if that happens there is a possibility of getting an
IntegrityError when trying to create the Commit object

this commit solves this problem by using get_or_create to
create the Commit object in the serializer

Signed-off-by: joseph-sentry <joseph.sawaya@sentry.io>
@joseph-sentry joseph-sentry merged commit f85b724 into main Mar 12, 2024
19 of 20 checks passed
@joseph-sentry joseph-sentry deleted the joseph/get-or-create-commit branch March 12, 2024 18:33
RulaKhaled pushed a commit that referenced this pull request Mar 13, 2024
* fix: use get_or_create in CommitSerializer.create

there is a possibility of creating commits concurrently
if that happens there is a possibility of getting an
IntegrityError when trying to create the Commit object

this commit solves this problem by using get_or_create to
create the Commit object in the serializer

* test: add test to make sure CommitSerializer create only creates one object in the db

---------

Signed-off-by: joseph-sentry <joseph.sawaya@sentry.io>
RulaKhaled added a commit that referenced this pull request Mar 13, 2024
* Test with states

* second round

* Okta stuff

* quick fix for test

* fixing tests

* more tests

* test: fix query measurements after 30 days test (#442)

* test: fix query measurements after 30 days test

This test started failing ater 2024-03-10 because
the time at the query was not frozen to a specific
date so it was using the system's actual time and
the measurements were not a part of the last 30 days.

* fix: add comments to clarify test fix

Signed-off-by: joseph-sentry <joseph.sawaya@sentry.io>

* [admin] allow trial extension for orgs currently on trial (#438)

Currently the admin app can extend a org trial, but only after they have expired and turned back to basic plan.
This change allows the orgs' trials to be extended while they're still trialing.

* Bundle Analysis: delete old code (#444)

These fields are being deprecated by bundleData and bundleChange. The app is no longer calling these fields anymore, it is safe to remove now.

* fix: use get_or_create in CommitSerializer.create (#437)

* fix: use get_or_create in CommitSerializer.create

there is a possibility of creating commits concurrently
if that happens there is a possibility of getting an
IntegrityError when trying to create the Commit object

this commit solves this problem by using get_or_create to
create the Commit object in the serializer

* test: add test to make sure CommitSerializer create only creates one object in the db

---------

Signed-off-by: joseph-sentry <joseph.sawaya@sentry.io>

* Revert "Bundle Analysis: delete old code (#444)" (#445)

This reverts commit 7932e93.

* Remove state after login

---------

Signed-off-by: joseph-sentry <joseph.sawaya@sentry.io>
Co-authored-by: joseph-sentry <136376984+joseph-sentry@users.noreply.github.com>
Co-authored-by: JerrySentry <142266253+JerrySentry@users.noreply.github.com>
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.

None yet

2 participants