-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Reorganize Stock::SimpleCoordinator
for improved debugging
#5249
Reorganize Stock::SimpleCoordinator
for improved debugging
#5249
Conversation
8b67af0
to
d51c22e
Compare
Codecov Report
@@ Coverage Diff @@
## main #5249 +/- ##
=======================================
Coverage 88.71% 88.71%
=======================================
Files 563 563
Lines 13890 13896 +6
=======================================
+ Hits 12322 12328 +6
Misses 1568 1568
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to improve this and submitting your collaboration ❤️ I don't see any breaking change and I'm sure that will help other developers!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Nice, and now those variables are easier to deprecate if we need to change or eliminate them one day.
@BenMorganIO I saw that the coverage decreased a bit with this PR (see failing check). I think it's related to all the new public methods added that are never tested. Maybe it can be fixed "easily" by testing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not in favour of adding to the API of our objects for debugging purposes, but I've spent enough time debugging this class that I'm willing to go along regardless. 😄
That said, is there a way to make it explicit that these methods are not part of the official public API of this class? I would rather we not end up going through a deprecation cycle for a bunch of methods that are public only for debugging purposes when this class inevitably changes.
@jarednorman we could prefix them with an underscore? That seems to tell devs not to trust that piece of the API from remaining consistent. |
attr_reader :order, :inventory_units, :splitters, :stock_locations, | ||
:filtered_stock_locations, :inventory_units_by_variant, :desired, | ||
:availability, :allocator, :packages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than use underscores or something, we can just make it explicit.
attr_reader :order, :inventory_units, :splitters, :stock_locations, | |
:filtered_stock_locations, :inventory_units_by_variant, :desired, | |
:availability, :allocator, :packages | |
attr_reader :order | |
# This class is notoriously opaque. To aid in debugging, we've provided | |
# the following methods. These are not considered part of the public API | |
# of this class and may be removed without deprecation in a future | |
# version of Solidus. Do not use them in production code. | |
attr_reader :inventory_units, :splitters, :stock_locations, | |
:filtered_stock_locations, :inventory_units_by_variant, :desired, | |
:availability, :allocator, :packages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@api private
should also do the trick 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏🏻 Perfect!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BenMorganIO did you see this comment about using @api private
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BenMorganIO, what do you think about just using @api private
? This one is very close to being merged 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, I did it myself 🙂
@jarednorman, are you ok with merging it now?
9f11959
to
6355850
Compare
Stock::SimpleCoordinator
for improved debugging
Summary
This is all about making it easier for a developer to debug issues when they get the dreaded
The first step we wanted to take was to make the instance variables accessible to the developer. A developer's journey to this issue is likely going to be discovering
Spree::Order#create_proposed_shipments
is what's failing. Then discovering that it builds an instance of this class. After that, they're going to want to start looking into the data that is set. Since they're all instance variables, they would likely want to be able to access some of the data.However, what the developer will soon realize is that it's the shipping rates that are holding back the shipments from being validated. So the real issue likely lies in an empty array being returned from:
If this is the issue, we'll want them to be able to easily recreate the packages the same way the class builds the packages. We've reorchestrated how the packages are built into a
build_packages
method and stored it there. I've also taken the time to simplify whatbuild_shipments
does so they can utilize that code as well.One other issue I noticed was that there was a global
Spree::StockLocation.all
. In a normal store, there will likely not be many, but in a marketplace, there could be thousands - so let's give them a method to easily make that code more intelligent if needed.I hope this work also makes it easier for the developer to extend this class.
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed: