- 🇮🇱Israel jsacksick
We can do this from an event subscriber too (we already have a shipments subscriber).
- Status changed to Needs review
almost 2 years ago 8:17am 15 February 2023 -
jsacksick →
committed 37b4a52b on 8.x-2.x
Issue #3307180 by khiminrm, jsacksick, rszrama, marchuk.vitaliy: Delete...
-
jsacksick →
committed 37b4a52b on 8.x-2.x
- Status changed to Fixed
almost 2 years ago 8:28am 15 February 2023 Automatically closed - issue fixed for 2 weeks with no activity.
- Status changed to Fixed
over 1 year ago 2:20pm 17 March 2023 - 🇺🇸United States lisastreeter
Took me a while to track down the cause of this error message that appeared after updating my site's modules:
Drupal\Core\Entity\EntityStorageException: Update existing 'profile' entity while changing the ID is not supported.
Realized it was this issue affecting custom code in which I delete an order's shipment after it's placed:
$shipment->delete();
Leaving this comment here in case anybody else gets the EntityStorageException error message and is looking for a fix. Adding this to my custom code, right before the delete, eliminated my bug:
$shipment->set('shipping_profile', NULL);
- 🇮🇱Israel jsacksick
@lisastreeter: Are you saying this patch introduced a bug? Or is this due to custom code on your site?
- 🇺🇸United States lisastreeter
@jacksick. Sorry I was unclear! Totally due to custom code on my site. Not the fault of the patch.
I only posted a message because it took me a little while to figure out why my checkout was broken after making a bunch of module updates. My custom code takes the shipping profile from the shipment and adds it directly to the order. So admins can easily edit both the billing and shipping addresses on the order form, side-by-side. We don't actually need the "shipment" after checkout. So I was just deleting it in custom event subscriber after attaching the shipping profile to the order. Patch did its job and deleted the shipment's shipping profile, but my custom code was assuming shipping profile still existed. Removing the reference before deleting the shipment was a simple one line fix in my custom code once I figured out what was happening.
- 🇺🇸United States rhovland Oregon
We are also experiencing issues due to this commit. We're deleting shipments via JSON API and then recreating them and linking the profile to the new shipment. This is causing the profile to disappear.
The issue description says "Delete a shipment's profiles when it is deleted on order deletion" but this code deletes the shipment profile even if the order still exists. I'd consider that a regression.
- 🇺🇸United States lisastreeter
@rhovland I agree that the title of the issue doesn't really match the code in the patch. Though generally I do think it's a good idea to delete the referenced entities that belong to an entity when the entity is deleted.
It may have been easier to identify potential issues in custom code if the title was, "Delete a shipment's profile when shipment is deleted." And perhaps the Release could have included a note about the possibility that shipment deletion within custom code could require rework.
- 🇺🇸United States rhovland Oregon
So it looks like this patch is technically correct and we're doing it wrong via JSON:API.
However, if anyone is currently experiencing this problem and needs a quick fix to prevent profiles from being deleted when the shipment still exists here's a patch that adds that check. This definitely won't get committed.
- 🇳🇱Netherlands finne Amsterdam
Thanks rhovland, I had the same problem: we are deleting shipments using a custom action in the GUI. Since this commit the shipment's profiles are also deleted: in our case we linked the order billing profile. So that was gone too.
We should probably rework the usage of profiles, but the patch is very welcome in the meantime.
Yeah, noticing this in migrations as well, rolling back shipments causes all the shipping profiles to get deleted.