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

Remove call to private method #update_cancellations from OrderUpdater#recalculate_adjustments #5633

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Jan 27, 2024

Summary

This removes the final occurrence of Spree::Adjustment#recalculate.

Order Cancellation adjustments are always finalized, and recalculating them is always a no-op. No need to carry the code path forward.

See https://github.com/solidusio/solidus/blob/main/core/app/models/spree/unit_cancel.rb#L27
and https://github.com/solidusio/solidus/blob/main/core/app/models/spree/adjustment.rb#L101

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.

@mamhoff mamhoff requested a review from a team as a code owner January 27, 2024 13:03
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Jan 27, 2024
Copy link

codecov bot commented Jan 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4b46992) 88.56% compared to head (9d249a3) 88.55%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5633      +/-   ##
==========================================
- Coverage   88.56%   88.55%   -0.01%     
==========================================
  Files         685      685              
  Lines       16408    16406       -2     
==========================================
- Hits        14531    14528       -3     
- Misses       1877     1878       +1     

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

Unit cancel adjustments are always finalized, and will thus never be
recalculated. Attempting to do so by un-finalizing them will result in a
ZeroDivisionError. Let's not try.
@mamhoff mamhoff force-pushed the remove-cancellation-recalculate-code-path branch from 075f11e to 9d249a3 Compare January 27, 2024 20:14
@mamhoff mamhoff changed the title Add Spree::OrderCancellations#recalculate_adjustments Never recalculate cancellation adjustments Jan 27, 2024
@@ -114,7 +114,6 @@ def recalculate_adjustments
# http://www.boe.ca.gov/formspubs/pub113/
update_promotions
update_taxes
update_cancellations
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking this may be a breaking change for stores that for some reason customized update_cancellations. The deprecation message would never show, since the method is not called anymore. So, I'm wondering if just deprecating would be a safer approach initially, and just remove it later... @mamhoff what's your opinion on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As long as the thing goes away at some point. Sure, I'll leave it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually... That makes our test suite extremely loud, to the point that we would not see any meaningful deprecation warnings. This warning is IMO not particularly meaningful, as I cannot imagine people having overridden this code path. If they have, they hopefully have at least one test for it where the deprecation message would show.

Copy link
Member

Choose a reason for hiding this comment

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

It's a private method, I agree that we should not get to this level of safety for backward compatibility. Still, a mention in the changelog/upgrade guide will be needed.

Copy link
Member

@spaghetticode spaghetticode Jan 30, 2024

Choose a reason for hiding this comment

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

@kennyadsl how do we manage this kind of mentions now? In other words: I guess it's not going to show up automatically that we removed a private method, so how will we remember to add the information to the changelog?
Could simply changing the PR title to something like "Remove call to private method OrderUpdater# update_cancellations from #recalculate_adjustments be enough?

Copy link
Member

Choose a reason for hiding this comment

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

I think that updating the description of the PR is enough, keeping in mind that whoever will release will take a look at the description to build the changelog. We might want to create a label if you think it's needed.

Copy link
Member

@spaghetticode spaghetticode Jan 30, 2024

Choose a reason for hiding this comment

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

@kennyadsl I agree the title change should suffice.
@mamhoff do you prefer to update the PR title personally or is it OK if we do it on your behalf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please, do it on my behalf. You know best how you want this change to appear in the change log.

@kennyadsl
Copy link
Member

Curious: are there no specs for this? I have the feeling we can remove some specs, maybe they are just not failing. Did you already check, @mamhoff?

@mamhoff
Copy link
Contributor Author

mamhoff commented Jan 29, 2024

Curious: are there no specs for this? I have the feeling we can remove some specs, maybe they are just not failing. Did you already check, @mamhoff?

There's no mention anywhere in the project of the name of the deprecated method, not in specs, nor is it called from anywhere else. Also, I've tried testing the behavior, and it's hard: It's a no-op, and if you make it some kind of op (by e.g. removing finalized: true from the adjustment) you run into all kinds of other errors, because the UnitCancel#compute_amount is not idempotent (it'll calculate a different total value of the line item depending on the number of unit_cancel adjustments present).

Pretty sure there's no tests for this.

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.

Nice. Remove this confusing behavior

@spaghetticode spaghetticode changed the title Never recalculate cancellation adjustments Remove call to private method #update_cancellations from OrderUpdater#recalculate_adjustments Jan 31, 2024
@spaghetticode spaghetticode merged commit c9b62b1 into solidusio:main Feb 1, 2024
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants