[GlitchTip] INSIGHTS-HCCM-STAGE-5HT: Fix IntegrityError race in report period save - #6259
Draft
koku-ci-triager-bot wants to merge 1 commit into
Draft
Conversation
Wrap report_period.save() in schema_context and catch IntegrityError so that a provider deleted mid-run doesn't surface as an unhandled exception. Matches the pattern used in ocp_cloud_parquet_summary_updater. Fixes GlitchTip INSIGHTS-HCCM-STAGE-5HT (issue 4499889). Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideWraps report_period.save() with proper tenant schema context and guards against IntegrityError when providers are deleted during cost model processing, preventing noisy GlitchTip errors from a foreign key race condition. Sequence diagram for report_period.save with schema_context and IntegrityError guardsequenceDiagram
participant OcpCostModelCostUpdater
participant schema_context
participant ReportPeriod
participant Database
participant LOG
OcpCostModelCostUpdater->>ReportPeriod: distribute_costs_and_update_ui_summary(summary_range)
OcpCostModelCostUpdater->>ReportPeriod: set derived_cost_datetime
OcpCostModelCostUpdater->>schema_context: schema_context(_schema)
activate schema_context
schema_context->>ReportPeriod: save()
ReportPeriod->>Database: INSERT/UPDATE report_period
alt provider_fk_intact
Database-->>ReportPeriod: success
ReportPeriod-->>schema_context: return
schema_context-->>OcpCostModelCostUpdater: continue processing
else provider_deleted_fk_violation
Database-->>ReportPeriod: IntegrityError
ReportPeriod-->>schema_context: raise IntegrityError
schema_context-->>OcpCostModelCostUpdater: IntegrityError
OcpCostModelCostUpdater->>LOG: warning(log_json(...))
OcpCostModelCostUpdater-->>OcpCostModelCostUpdater: return (skip report period update)
end
deactivate schema_context
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (57.1%) is below the target coverage (90.0%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #6259 +/- ##
=======================================
- Coverage 94.4% 94.4% -0.0%
=======================================
Files 369 369
Lines 33438 33444 +6
Branches 3730 3730
=======================================
- Hits 31567 31565 -2
- Misses 1211 1218 +7
- Partials 660 661 +1 🚀 New features to boost your workflow:
|
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.
GlitchTip
https://glitchtip.devshift.net/insights-hccm-stage/issues/4499889
Classification
code_fixable
Summary
distribute_costs_and_update_ui_summaryinocp_cost_model_cost_updater.pycallsreport_period.save()without aschema_contextwrapper and without catchingIntegrityError. When a provider is deleted while cost model processing is in-flight, the FK constraintreporting_ocpusagere_provider_id_7348fe66_fk_reportingfires and the exception bubbles up unhandled, causing 11+ error events in GlitchTip.Root cause: Missing
schema_contextwrapper (needed for django-tenants ORM routing) and no guard for the provider-delete race condition.Fix: Wrap
report_period.save()inwith schema_context(self._schema)and catchIntegrityErrorwith a warning log + early return. This matches the pattern used inocp_cloud_parquet_summary_updater.py:299.Generated by GlitchTip Triager (Ambient Code). Review before merge.
Summary by Sourcery
Bug Fixes: