Rework report_id generation and fix generate_audit_indexes#4896
Conversation
- Now using SQL to get the next ID. - We are now getting this ID in every instance where we generate a SAC, and pass it as the `id` for the new SAC object. - Audits currently pull the ID directly from the SAC. Once we deprecate the SAC, we will make the same adjustments for the Audit.
|
This pull request is not up to date with main. Please merge main into this brach or rebase this branch onto main. This PR should not be approved until all status checks pass. If you see this message, please rerun all status checks before merging. |
|
Terraform plan for meta No changes. Your infrastructure matches the configuration.✅ Plan applied in Deploy to Development and Management Environment #988 |
|
Terraform plan for dev Plan: 1 to add, 0 to change, 1 to destroy.Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement
Terraform will perform the following actions:
# module.dev.module.cors.null_resource.cors_header must be replaced
-/+ resource "null_resource" "cors_header" {
!~ id = "*******************" -> (known after apply)
!~ triggers = { # forces replacement
!~ "always_run" = "2025-04-15T22:20:51Z" -> (known after apply)
}
}
Plan: 1 to add, 0 to change, 1 to destroy.✅ Plan applied in Deploy to Development and Management Environment #988 |
|
This pull request is not up to date with main. Please merge main into this brach or rebase this branch onto main. This PR should not be approved until all status checks pass. If you see this message, please rerun all status checks before merging. |
|
This pull request is not up to date with main. Please merge main into this brach or rebase this branch onto main. This PR should not be approved until all status checks pass. If you see this message, please rerun all status checks before merging. |
|
jadudm
left a comment
There was a problem hiding this comment.
LGTM. Sets us up to transition to new sequences as part of the transition.
Addresses part of #4859.
We realized a problem with the current report_id generation. We originally have been using
.count(). However, now that we have the ability to deleteflagged_for_removalrecords, this will affect the report_id generation in a negative way.This PR makes a change so that the report_id relies on the latest integer provided by the ID sequence. Because we are getting the sequence ID, we must pass this ID manually on SAC creation. Otherwise, Django will automatically add another +1 to the ID, meaning every new record we add to the DB will add +2 to the sequence counter.
get_next_sequence_id
This is a new method in
audit/models.utils.pywhich grabs the sequence ID from whatever table is passed to it. This fetch will result in incrementing the counter by 1. So, we have to use the ID returned and pass it to bothgenerate_sac_report_id()AND theidof the record on creation.This change has been reflected in the submission logic as well as our unit tests.
generate_audit_indexes
On a very small note, we are referencing an undefined value in
generate_audit_indexes. This was causing our tests on staging to fail last week. I made an adjustment in this PR to correct this.How to test
PR Checklist: Submitter
maininto your branch shortly before creating the PR. (You should also be mergingmaininto your branch regularly during development.)git status | grep migrations. If there are any results, you probably need to add them to the branch for the PR. Your PR should have only one new migration file for each of the component apps, except in rare circumstances; you may need to delete some and re-runpython manage.py makemigrationsto reduce the number to one. (Also, unless in exceptional circumstances, your PR should not delete any migration files.)PR Checklist: Reviewer
make docker-clean; make docker-first-run && docker compose up; then rundocker compose exec web /bin/bash -c "python manage.py test"The larger the PR, the stricter we should be about these points.
Pre Merge Checklist: Merger
-/+ resource "null_resource" "cors_header"should be destroying and recreating its self and~ resource "cloudfoundry_app" "clamav_api"might be updating itssha256for thefac-file-scannerandfac-av-${ENV}by default.main.