[COST-7501] fix DiskCapacity scraper IntegrityError#6063
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the Azure storage capacity scraping task to use update_or_create instead of get_or_create, ensuring that existing records are updated when capacities change. A new test case was added to verify this behavior. Feedback suggests moving provider_type to the defaults dictionary in the update_or_create call to prevent potential IntegrityError collisions if product_substring is the primary key.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6063 +/- ##
=====================================
Coverage 94.4% 94.4%
=====================================
Files 362 362
Lines 32101 32101
Branches 3538 3538
=====================================
Hits 30290 30290
Misses 1176 1176
Partials 635 635 🚀 New features to boost your workflow:
|
bacciotti
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira Ticket
COST-7501
Description
This change fixes an
IntegrityErrorin thescrape_azure_storage_capacitiesThe task used
get_or_createwithproduct_substring,capacity, andprovider_typeas lookup fields. Sinceproduct_substringis the primary key, only one row per SKU can exist. When the scraped capacity differs from the stored value, the GET fails (no match on capacity) and the CREATE fails (PK already exists), resulting in an unhandledIntegrityError.Testing
pipenv run python koku/manage.py test masu.test.celery.test_tasks.TestCeleryTasks.test_scrape_azure_storage_capacities masu.test.celery.test_tasks.TestCeleryTasks.test_scrape_azure_storage_capacities_updates_stale_capacity masu.test.celery.test_tasks.TestCeleryTasks.test_error_scrape_azure_storage_capacities --no-input -v 2test_scrape_azure_storage_capacities_updates_stale_capacitywhich pre-seeds a row with a stale capacity and verifies the scraper updates it.Release Notes
* Fix IntegrityError in scrape_azure_storage_capacities