Skip to content

[COST-7501] fix DiskCapacity scraper IntegrityError#6063

Merged
djnakabaale merged 2 commits into
mainfrom
fix-diskcap-update-or-create
May 20, 2026
Merged

[COST-7501] fix DiskCapacity scraper IntegrityError#6063
djnakabaale merged 2 commits into
mainfrom
fix-diskcap-update-or-create

Conversation

@djnakabaale
Copy link
Copy Markdown
Contributor

@djnakabaale djnakabaale commented May 15, 2026

Jira Ticket

COST-7501

Description

This change fixes an IntegrityError in the scrape_azure_storage_capacities
The task used get_or_create with product_substring, capacity, and provider_type as lookup fields. Since product_substring is 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 unhandled IntegrityError.

Testing

  1. Checkout branch.
  2. Run the unit tests:
    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 2
    1. All 3 tests should pass, including the new test_scrape_azure_storage_capacities_updates_stale_capacity which pre-seeds a row with a stale capacity and verifies the scraper updates it.

Release Notes

  • proposed release note
* Fix IntegrityError in scrape_azure_storage_capacities

@djnakabaale djnakabaale added the azure-smoke-tests pr_check will run azure + ocp on azure smoke tests, used when changes affect azure only. label May 15, 2026
@github-actions github-actions Bot added the smokes-required Label to show that smokes tests should be run against these changes. label May 15, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread koku/masu/celery/tasks.py
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.4%. Comparing base (9da32c9) to head (40e2372).

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@djnakabaale djnakabaale changed the title fix DiskCapacity scraper IntegrityError by switching to update_or_create [COST-7501] fix DiskCapacity scraper IntegrityError May 19, 2026
@djnakabaale djnakabaale marked this pull request as ready for review May 19, 2026 16:59
@djnakabaale djnakabaale requested review from a team as code owners May 19, 2026 16:59
@djnakabaale djnakabaale merged commit 17f4089 into main May 20, 2026
13 checks passed
@djnakabaale djnakabaale deleted the fix-diskcap-update-or-create branch May 20, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure-smoke-tests pr_check will run azure + ocp on azure smoke tests, used when changes affect azure only. smokes-required Label to show that smokes tests should be run against these changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants