Skip to content

LG-16075: Duplicate submission error handling at sign up completion#12273

Merged
jmdembe merged 16 commits intomainfrom
jd/LG-16075-duplicate_signup_handling
Jul 1, 2025
Merged

LG-16075: Duplicate submission error handling at sign up completion#12273
jmdembe merged 16 commits intomainfrom
jd/LG-16075-duplicate_signup_handling

Conversation

@jmdembe
Copy link
Contributor

@jmdembe jmdembe commented Jun 18, 2025

🎫 Ticket

LG-16075

🛠 Summary of changes

This PR seeks to stop the ActiveRecord::RecordNotUnique from happening when a user submits the "Agree and Continue" button on the sign_up/completed screen.

changelog: Bug Fixes, sign up completion, fix double submission at sign in completion
@jmdembe jmdembe requested review from mdiarra3 and vrajmohan June 18, 2025 19:30
@mitchellhenke
Copy link
Contributor

Could the checks be moved closer to where the database call is raising an exception, I think it's somewhere here based on the ticket description.

This is potentially also a case for create_or_find_by, we addressed a similar issue with it in #6524.

@jmdembe
Copy link
Contributor Author

jmdembe commented Jun 23, 2025

Could the checks be moved closer to where the database call is raising an exception, I think it's somewhere here based on the ticket description.

This is potentially also a case for create_or_find_by, we addressed a similar issue with it in #6524.

I see. We are doing a create_or_find_by in one method where one does a create and the other does a find. Maybe this would be a time to refactor?

Comment on lines -62 to -66
ai = AgencyIdentity.find_by(uuid: @sp_identity.uuid)
return ai if ai
sp = ServiceProvider.find_by(issuer: @sp_identity.service_provider)
return unless agency_id(sp)
AgencyIdentity.find_by(agency_id: agency_id, user_id: @sp_identity.user_id)
Copy link
Contributor

@mitchellhenke mitchellhenke Jun 23, 2025

Choose a reason for hiding this comment

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

If I'm reading this right, this method:

  1. Tries to find an AgencyIdentity based only on the ServiceProviderIdentity uuid
  2. If there isn't one, and the service provider has an agency association, it tries to find an AgencyIdentity based on the agency_id and user_id

The above find_agency_identity method that replaces it doesn't have the same behavior, I'm not sure if that will cause issues.

Copy link
Contributor

Choose a reason for hiding this comment

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

I pushed up commit e2208d9 with a new test that fails with the current changes.

@jmdembe jmdembe force-pushed the jd/LG-16075-duplicate_signup_handling branch from a8f54bf to a17c544 Compare June 23, 2025 20:09
@jmdembe jmdembe requested a review from mitchellhenke June 24, 2025 15:04
uuid: uuid,
)
) do |ai|
ai.uuid = uuid
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this set the UUID to the same UUID it would have otherwise had? If so, can it be deleted?

Copy link
Contributor Author

@jmdembe jmdembe Jun 24, 2025

Choose a reason for hiding this comment

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

Yes it does. Deleted in b6e2cfe.

@jmdembe jmdembe requested a review from mitchellhenke June 24, 2025 16:48

uuid = spi&.uuid || SecureRandom.uuid
AgencyIdentity.create(
AgencyIdentity.find_or_create_by(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that this is the right method to be changing, the error was in sign up, but this method is only called in an Attempts API class: https://github.com/18F/identity-idp/blob/2fc19c9/app/services/attempts_api/tracker.rb#L98-L102

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So are you saying to do the call at the point of sign up? Because if we are to do that, we would have to do the same logic that is in the above link, no?
Also, wouldn't this also reduce the chance of a race condition in the Attempts API class? Or does that not matter?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I was intending to say that the exception occurred during sign up, which calls find_or_create_agency_identity further down, and that's probably where any changes would need to occur.

Copy link
Contributor

Choose a reason for hiding this comment

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

can u change this back to just create please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My mistake. Changed in 2f448c0.

@jmdembe jmdembe force-pushed the jd/LG-16075-duplicate_signup_handling branch from 815ab28 to f6479d9 Compare June 26, 2025 16:54
@jmdembe jmdembe requested a review from mitchellhenke June 26, 2025 17:58
AgencyIdentity.find_by(agency_id: agency_id, user_id: @sp_identity.user_id)

begin
AgencyIdentity.create(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is effectively create_or_find_by, could we use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I wrote this, I did not use create_or_find_by because Agency.create requires three arguments while Agency.find_by requires two. Adding the UUID to the find makes the links identities from 2 sps test fail, so that is why I went back to begin...rescue

Copy link
Contributor

Choose a reason for hiding this comment

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

I think he is saying u can use create or find_by in this line here instead of the begin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe I changed that in 995b5e2. There are tests failing now that didn't when I used begin...create that I am struggling to understand.

@jmdembe
Copy link
Contributor Author

jmdembe commented Jun 27, 2025

For 1776946, is this a viable solution, and if so, how can a test be written for this case?

@jmdembe jmdembe requested a review from mitchellhenke June 30, 2025 13:34
@mitchellhenke
Copy link
Contributor

For 1776946, is this a viable solution, and if so, how can a test be written for this case?

I'm not sure that putting it in a transaction is sufficient in this case.

@mdiarra3 mdiarra3 self-requested a review June 30, 2025 14:57
@jmdembe jmdembe force-pushed the jd/LG-16075-duplicate_signup_handling branch from 1776946 to 995b5e2 Compare June 30, 2025 17:30
@jmdembe jmdembe merged commit e649880 into main Jul 1, 2025
1 check passed
@jmdembe jmdembe deleted the jd/LG-16075-duplicate_signup_handling branch July 1, 2025 13:04
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.

3 participants