Skip to content

Backfill reset pending timestamp on profiles with expired IPP enrollment#11130

Closed
aduth wants to merge 2 commits intomainfrom
aduth-backfill-expired-ipp-verification-at
Closed

Backfill reset pending timestamp on profiles with expired IPP enrollment#11130
aduth wants to merge 2 commits intomainfrom
aduth-backfill-expired-ipp-verification-at

Conversation

@aduth
Copy link
Copy Markdown
Contributor

@aduth aduth commented Aug 22, 2024

🛠 Summary of changes

Creates a Rake task to update profiles associated with expired in-person proofing enrollments, to reset the value of the profile's pending status and timestamp.

This is an alternative to a solution which involves updating queries to accommodate this mixed state: #11129

📜 Testing Plan

Override config/application.yml to prevent results job from automatically marking pending profiles as successful in local development:

in_person_enrollments_ready_job_cron: 0 0 29 2 1
  1. Have both the IdP and sample application running simultaneously
  2. In a private browsing window, go to http://localhost:9292
  3. Change "Level of Service" to "Identity-verified"
  4. Click "Sign in"
  5. Create a new account
  6. Complete identity verification using in-person proofing
  7. Once you reach the barcode step, close your browser
  8. Open a rails console: rails console
  9. Manually mark the enrollment as expired, without updating associated profile (simulate behavior prior to LG-14231: Users can't access accounts after enrollment expires #11105): InPersonEnrollment.last.update(status: :expired)
  10. Run the Rake task to update profiles: rake profiles:backfill_expired_pending_in_person_verification UPDATE_PROFILES=true
  11. Observe at least one line of output from the previous command
  12. Repeat Steps 2-4
  13. Sign in with the account you created previously

Before: You'd be redirected to the account page (wrong), and the account page would raise an exception when trying to access due_date property on the pending enrollment
After: You're redirected into the identity verification flow

changelog: Internal, Data Normalization, Backfill reset pending timestamp on profiles with expired in-person enrollment
Comment on lines +93 to +96
profiles = InPersonEnrollment.where(status: :expired).
includes(:profile).
where.not(profile: { in_person_verification_pending_at: nil }).
map { |enrollment| enrollment.profile }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The idea with doing it inverted like this is that I'd assume there's much fewer records in the in-person enrollment table than in the profile table, and since we don't have any indices to leverage to optimize the query, this should hopefully be more efficient.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if we're worried about query time and table size, we could also try in_batches which breaks down the query into batches by ID (docs link)

Suggested change
profiles = InPersonEnrollment.where(status: :expired).
includes(:profile).
where.not(profile: { in_person_verification_pending_at: nil }).
map { |enrollment| enrollment.profile }
profiles = InPersonEnrollment.where(status: :expired).
includes(:profile).
where.not(profile: { in_person_verification_pending_at: nil }).
in_batches.flat_map do |batch|
batch.map { |enrollment| enrollment.profile }
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Checking this with production data, I think it should probably be fine enough. I didn't even need to adjust the default timeout when running test queries.

@aduth
Copy link
Copy Markdown
Contributor Author

aduth commented Aug 28, 2024

Going to close this to be handled in LG-14320

@aduth aduth closed this Aug 28, 2024
@aduth aduth deleted the aduth-backfill-expired-ipp-verification-at branch August 28, 2024 16:23
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.

2 participants