Skip to content

Fix shipment adjustments not persisting on order recalculate#6334

Merged
tvdeyen merged 1 commit intosolidusio:mainfrom
SuperGoodSoft:autosave-changed-shipment-adjustments
Oct 21, 2025
Merged

Fix shipment adjustments not persisting on order recalculate#6334
tvdeyen merged 1 commit intosolidusio:mainfrom
SuperGoodSoft:autosave-changed-shipment-adjustments

Conversation

@Noah-Silvera
Copy link
Contributor

@Noah-Silvera Noah-Silvera commented Oct 17, 2025

Summary

A commit was made in #6315 (5979f25) in service of the in memory order updater #5872 that changed the behavior in the OrderTaxation class to set the adjustment value but not persist it. Instead, the persistence happens when the order is saved. If a shipment is changed, and an associated adjustment is changed, the shipment adjustment will be autosaved when the order is.

However, if a shipment is not changed, but the adjustment is, the adjustment will not be autosaved when the order is.

In #6315, we ensured that these changed associations cannot get left behind by setting autosave: true, which forces the model to check if it has any associations that need saving instead of telling it's relation "nope I haven't changed"

We can do the same thing here for the shipment to ensure changing adjustments will make the shipment tell it's order "I have changed", even if none of it's direct properties have changed.

You can test this change by removing the autosave: true option the adjustments and running 'when the address has changed to a different state' specs. They fail with the error "expected order.shipments.first.adjustments.first.amount to have changed from 1 to 2, but did not change", demonstrating a scenario where the shipment adjustment changes do not get persisted.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Oct 17, 2025
@Noah-Silvera Noah-Silvera changed the title Autosave shipment adjustments to persist taxes on recalculate Fix shipment adjustments not persisting on order recalculate Oct 17, 2025
@Noah-Silvera Noah-Silvera force-pushed the autosave-changed-shipment-adjustments branch from 75effa5 to f05775e Compare October 17, 2025 19:35
@Noah-Silvera Noah-Silvera marked this pull request as ready for review October 17, 2025 19:35
@Noah-Silvera Noah-Silvera requested a review from a team as a code owner October 17, 2025 19:35
Copy link
Contributor

@benjaminwil benjaminwil left a comment

Choose a reason for hiding this comment

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

Thanks for finding this!

I think it would make sense to release this in a 4.6.1 patch. 💯

@codecov
Copy link

codecov bot commented Oct 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.35%. Comparing base (d070f94) to head (b47e0f0).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6334   +/-   ##
=======================================
  Coverage   89.35%   89.35%           
=======================================
  Files         961      961           
  Lines       20195    20195           
=======================================
  Hits        18046    18046           
  Misses       2149     2149           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

A commit was made in solidusio#6315 (5979f25) in service of the in memory order updater solidusio#5872 that changed the behavior in the OrderTaxation class to set the adjustment value but not persist it. Instead, the persistence happens when the order is saved. If a shipment is changed, and an associated adjustment is changed, the shipment adjustment will be autosaved when the order is.

However, if a shipment is *not* changed, but the adjustment is, the adjustment will *not* be autosaved when the order is.

In solidusio#6315, we ensured that these changed associations cannot get left behind by setting `autosave: true`, which forces the model to check if it has any associations that need saving instead of telling it's relation "nope I haven't changed"

We can do the same thing here for the shipment to ensure changing  adjustments will make the shipment tell it's order "I have changed", even if none of it's direct properties have changed.

You can test this change by removing the `autosave: true` option the adjustments and running 'when the address has changed to a different state' specs. They fail with the error "expected `order.shipments.first.adjustments.first.amount` to have changed from 1 to 2, but did not change", demonstrating a scenario where the shipment adjustment changes do not get persisted.
@Noah-Silvera Noah-Silvera force-pushed the autosave-changed-shipment-adjustments branch from f05775e to b47e0f0 Compare October 17, 2025 19:46
@Noah-Silvera
Copy link
Contributor Author

I think it would make sense to release this in a 4.6.1 patch. 💯

I thought so too!

@adammathys adammathys added the backport-v4.6 Backport this pull-request to v4.6 label Oct 17, 2025
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Great commit message. This is how it's supposed to be done 👏🏻

@tvdeyen tvdeyen merged commit e44896b into solidusio:main Oct 21, 2025
41 checks passed
@github-actions
Copy link

💚 All backports created successfully

Status Branch Result
v4.6

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v4.6 Backport this pull-request to v4.6 changelog:solidus_core Changes to the solidus_core gem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants