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

#4770: Don't crash on deleted item for event history #4876

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dorner
Copy link
Collaborator

@dorner dorner commented Dec 20, 2024

Resolves #4770.

Description

Fixes a crash on the history page when an item was deleted. Instead it will display Item {item id} (deleted).

Type of change

  • Bug fix (non-breaking change which fixes an issue)
image

@dorner dorner requested review from awwaiid and cielf December 20, 2024 15:28
@@ -11,7 +11,7 @@
<%= link_to storage_locs.find { |i| i.id == loc.id}.name, storage_location_path(loc.id) %>
<td>
<% loc.items.values.each do |entry| %>
<%= link_to items.find { |i| i.id == entry.item_id}.name, item_path(entry.item_id) %>:
<%= link_to items.find { |i| i.id == entry.item_id}&.name || "Item #{entry.item_id} (deleted)", item_path(entry.item_id) %>:
Copy link
Collaborator

@coalest coalest Dec 20, 2024

Choose a reason for hiding this comment

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

Don't you also have to apply this same fix in app/views/events/_event_row.html.erb as well?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also does it make sense to create a link to a deleted item? Won't it just lead to a 404?

Copy link
Collaborator

Choose a reason for hiding this comment

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

And looking into the future... maybe we would want to implement soft deletes for items, so that we could grab the items name here. Because it doesn't seem like displaying "Item 1234 (deleted)" will be very helpful for users.

Copy link
Collaborator

@cielf cielf Dec 20, 2024

Choose a reason for hiding this comment

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

@coalest, we only allow deletes per se on items that have had no transactions associated with them. Otherwise we allow deactivates if the inventory level on all storage locations for the item is 0.

This is dealing with a particular edge case . If we deleted an item that existed on the snapshot, it was making the event run crash.
It reall is an edge case, but could possibly happen again, as the intent is to do periodic refersher snapshots.

This report is about 90% for us, though I expect some of our most astute users will find it useful.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is essentially saying "nothing to see here. Move on."

@cielf
Copy link
Collaborator

cielf commented Dec 20, 2024

@dorner. I'm ok with the concept. I'm not sure how I manually test it, though.

@coalest
Copy link
Collaborator

coalest commented Dec 20, 2024

@cielf To reproduce a similar bug (not snapshot event but a different event):

  1. create a new item.
  2. create a new purchase with that item.
  3. delete the purchase.
  4. delete the item.
  5. go to the history page => 500

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.

Well, if I confirm the sequence @coalest suggested, then switch to this branch and try to bring up the history, it fails on the last page.. So there's still something amiss, and it would seem related.

@dorner
Copy link
Collaborator Author

dorner commented Dec 23, 2024

Added the fix for the other partial, and also removed the link for deleted items.

@cielf
Copy link
Collaborator

cielf commented Jan 5, 2025

@dorner This looks good for the example @coalest provided. Is there a command I can run in the console to do a new snapshot?

@dorner
Copy link
Collaborator Author

dorner commented Jan 7, 2025

SnapshotEvent.publish(organization) will do it.

@cielf
Copy link
Collaborator

cielf commented Jan 8, 2025

Alas. I have found a new problem.
Sequence:
log in as [email protected]
Create a new item
Do a purchase of 10 of that item
Run a snapshot
Delete the purchase

One would expect the level on the item to be 0 (and hence it could be deleted, for the testing of this PR).
It isn't. It is 10.

Hopefully there aren't any instances in the current "wild" but we can run a check on that.

Do you want to treat this as a separate issue?

@cielf
Copy link
Collaborator

cielf commented Jan 19, 2025

@dorner Just checking in case this has fallen through the cracks.

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.

[Bug] History fails with Snapshot including later-deleted item
3 participants