LG-16075: Duplicate submission error handling at sign up completion#12273
LG-16075: Duplicate submission error handling at sign up completion#12273
Conversation
changelog: Bug Fixes, sign up completion, fix double submission at sign in completion
|
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 |
| 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) |
There was a problem hiding this comment.
If I'm reading this right, this method:
- Tries to find an AgencyIdentity based only on the ServiceProviderIdentity uuid
- 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.
There was a problem hiding this comment.
I pushed up commit e2208d9 with a new test that fails with the current changes.
a8f54bf to
a17c544
Compare
| uuid: uuid, | ||
| ) | ||
| ) do |ai| | ||
| ai.uuid = uuid |
There was a problem hiding this comment.
Does this set the UUID to the same UUID it would have otherwise had? If so, can it be deleted?
|
|
||
| uuid = spi&.uuid || SecureRandom.uuid | ||
| AgencyIdentity.create( | ||
| AgencyIdentity.find_or_create_by( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
can u change this back to just create please.
815ab28 to
f6479d9
Compare
| AgencyIdentity.find_by(agency_id: agency_id, user_id: @sp_identity.user_id) | ||
|
|
||
| begin | ||
| AgencyIdentity.create( |
There was a problem hiding this comment.
This is effectively create_or_find_by, could we use that?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I think he is saying u can use create or find_by in this line here instead of the begin.
There was a problem hiding this comment.
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.
|
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. |
1776946 to
995b5e2
Compare
🎫 Ticket
LG-16075
🛠 Summary of changes
This PR seeks to stop the
ActiveRecord::RecordNotUniquefrom happening when a user submits the "Agree and Continue" button on thesign_up/completedscreen.