Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors found in testing #4122

Merged
merged 7 commits into from
Mar 4, 2024
Merged

Fix errors found in testing #4122

merged 7 commits into from
Mar 4, 2024

Conversation

dorner
Copy link
Collaborator

@dorner dorner commented Feb 18, 2024

@cielf this fixes the 2 issues we found so far:

  • Crash after creating a storage location
  • Not failing when reducing inventory via an edit

@dorner dorner requested a review from cielf February 18, 2024 21:34
@cielf
Copy link
Collaborator

cielf commented Feb 21, 2024

I don't know if this is specfic to this fix or if it would occur on main, but I was testing a bit using MHM, which appears to have some negative inventory items at this time, and when saving a Donation (of a different item) I got "Error occurred when re-running events: DistributionEvent on 2024-02-20: Could not reduce quantity by 1 - current quantity is 0 for Car Seat - Infant up to 22lbs. w/ handle in Main Warehouse" Sooooo.... we may need to do some data cleanup for this to work?

@dorner
Copy link
Collaborator Author

dorner commented Feb 22, 2024

Sounds right - we might need to identify organizations with negative inventory at the current time and maybe add an adjustment to set it back to zero? This PR tightens up our validations so it makes sense that something that worked before wouldn't now.

@cielf
Copy link
Collaborator

cielf commented Feb 22, 2024

Hrrrm. i managed to totally mung the inventory numbers. Magnitude: Took a value that was in the 20000 range down to negatives, and messed up all the numbers. I assumed it was to do with the above error, but no luck with the immediate recreation. I was checking a couple of other things, and going back and forth between flag on and flag off. So this is just a heads up until I recreate.

@cielf
Copy link
Collaborator

cielf commented Feb 22, 2024

Regarding the negative inventory -- I'm pretty sure we'll need to remove the old events and start with a fresh snapshot. There are some pretty large differences between the inventory we calculate with events, and what they are currently seeing on this org.

@cielf
Copy link
Collaborator

cielf commented Feb 22, 2024

Regarding the exception: I'm not sure adding an inventory adjustment would work. It's failing for something that happened in the past...

@cielf
Copy link
Collaborator

cielf commented Feb 23, 2024

Oh -- also on the donation -- I wasn't clear -- the error around the negative inventory is an uncaught error, so they'd get a 500. On the distribution, it is caught and presented as an error. (It would still be mightily confusing, and prevent them doing anything) Edit: purchase is behaving the same as donation.

@cielf
Copy link
Collaborator

cielf commented Feb 23, 2024

It does look like this is safe when the read_events flag is disabled though. I have not been able to recreate the problem with the inventory going kerfluey. I was hopping amongst 2 or 3 different branches, maybe that had something to do with it.

@cielf
Copy link
Collaborator

cielf commented Feb 23, 2024

I spent awhile testing this with the flag on, and it definitely does what I expect it to.

Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

As far as changes - could we make it so that that error regarding the negative inventory is caught on donation and purchase? Please check kit allocation too.

Otherwise, with some trepidation around not being able to recreate that crazy inventory issue (my apologies for not grabbing the events on that), it looks good.

@cielf
Copy link
Collaborator

cielf commented Feb 25, 2024

Found another problem that is related to the reduction of inventory. If you have that kind of error, at least in donation, the name of the item in question goes away, and you just have the item number. I can write this up as a separate issue if you prefer. (Edit: Looks like purchase is ok)(Further Clarification: Testing on seed, so this is not related to the error with the negative inventory from MGM.)

Screenshot 2024-02-25 at 8 40 16 AM

@cielf
Copy link
Collaborator

cielf commented Feb 26, 2024

@dorner One last thing -- that error is going to be pretty confusing if it ever comes up. What action should the user take if it does -- contact us? Or make an inventory adjustment? Maybe we can give them some guidance. ( I mean the error that comes up if there is negative inventory. I feel like it's a "something happened in the past that we can't get past" situation, rather than a "oh, just adjust the inventory" situation.)

@cielf
Copy link
Collaborator

cielf commented Mar 1, 2024

@dorner Whoops --the crash also happens on finalizing audit. Please address.

@dorner
Copy link
Collaborator Author

dorner commented Mar 1, 2024

Pushed a fix for the audit. If the error happens, for now I think they need to contact us. Should I add that to the error message? I feel like it's already pretty wordy.

@cielf
Copy link
Collaborator

cielf commented Mar 1, 2024

There really isn't anything else that we really want them to contact us for. It's an exceptional case (which I hope we never actually have once we get events fully implemented). So, yes. Please do have them contact us.

@cielf
Copy link
Collaborator

cielf commented Mar 1, 2024

@awwaiid -- can you do the tech review up to this point, please? (Handling the outstanding text change is well within my abilities to confidently o.k.)

@@ -82,7 +82,7 @@ def quantity_for(storage_location: nil, item_id: nil)

if storage_location
if item_id
@inventory.storage_locations[storage_location.to_i].items[item_id.to_i]&.quantity || 0
@inventory.storage_locations[storage_location.to_i]&.items&.dig(item_id.to_i)&.quantity || 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelatedly, I learned a while back that javascript's ? operator is short-cutting, so that the first one in a long chain immediately halts the whole sequence. I like the explicitness of Ruby's a bit better, though it ends up more verbose.

Copy link
Collaborator

@awwaiid awwaiid left a comment

Choose a reason for hiding this comment

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

Looks good -- almost entirely error handling.

@awwaiid awwaiid requested a review from cielf March 2, 2024 16:23
@dorner
Copy link
Collaborator Author

dorner commented Mar 3, 2024

@cielf added the extra text.

@cielf
Copy link
Collaborator

cielf commented Mar 3, 2024

@dorner There are a couple of suggestions from Brock -- could you take a quick look at them and confirm or deny? Thanks.

Co-authored-by: Brock Wilcox <awwaiid@thelackthereof.org>
@dorner
Copy link
Collaborator Author

dorner commented Mar 4, 2024

@cielf done.

@cielf cielf merged commit 10f1c81 into main Mar 4, 2024
20 checks passed
@cielf cielf deleted the event-read-fixes branch March 4, 2024 17:48
Copy link
Contributor

@dorner: Your PR Fix errors found in testing is part of today's Human Essentials production release: 2024.03.17.
Thank you very much for your contribution!

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.

None yet

3 participants