-
-
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
Improve payment service providers switching errors #3837
Improve payment service providers switching errors #3837
Conversation
My bad, I didn't pay attention to failing checks yet. |
@luca-landa I'm wondering if we may be interested in keeping for reference the original payment method information. For example, if we change the boolean field to a string, we can populate it with the previous |
@spaghetticode it seems a good idea to keep track of the previous But personally I would add it in another field, instead of converting the Do you think it can be a better solution? |
@luca-landa I don't have a strong opinion on this, I think there are pros and cons with both approaches. I don't see def deprecated?
deprecated_type.present?
end which would need to be explicitly written instead of relying on AR automatic definitions. The advantage in this case would be we just need to maintain a single field on the DB instead of 2. Also, we already have the boolean field On the other hand, the burden to maintain 2 fields is rather minimal, and it would probably allow us to write simpler code in ruby. |
@spaghetticode I agree on the potential problem of keeping I like your proposal with But I have another change in mind that would make the AR scope a bit more readable, and it would make the record more explicitly marked as "deprecated". I have another (OT) question about this PR: I don't know how exactly should I fix an error that I made, I could add another commit but it wouldn't satisfy the guidelines request that the specs pass for each commit. Should I create another PR for another branch? |
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 think we should find a better name for the "deprecated" column that aligns better with how it works. Otherwise, this seems like a reasonable approach if the method we're overriding has the desired effect.
core/db/migrate/20201108142424_add_deprecated_to_payment_method.rb
Outdated
Show resolved
Hide resolved
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! I left some questions on the implementation. Looking forward to know what you think about them.
Also, can you please squash the last commit into the one that introduced the code style issue?
🙏
core/db/migrate/20201108142424_add_deprecated_to_payment_method.rb
Outdated
Show resolved
Hide resolved
I guess that would make sense, although it's not strictly needed... but I think it may make it easier to discriminate removed payment methods and their payments? If while doing the PR you can come up with good reasons for doing (or not doing) it, you can add some comments in the commit message, that would be very valuable.
No need, you can make all the fixes and changes you need in this PR, as long as they're related to it. |
6d8a522
to
eae43dd
Compare
Well the I may just discard the idea, but stick with the idea of changing |
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.
Left a second review with other thoughts. Let me know if those make sense.
Another thing: I was wondering if there's something we could do when deleting a payment method. I'm thinking of a simple PORO that handles the PaymentMethod destruction and maybe sets these attributes for us when we (soft-)delete a payment method? This way we will also prevent this error from happening, anyway, maybe it's something for another PR. 🙂
core/db/migrate/20201108142424_add_deprecated_to_payment_method.rb
Outdated
Show resolved
Hide resolved
dd1eb08
to
a49d2ca
Compare
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.
Left some other comments, we are almost there, thanks again!
core/db/migrate/20201118200630_add_previous_type_to_spree_payment_methods.rb
Outdated
Show resolved
Hide resolved
a49d2ca
to
5839bfe
Compare
5839bfe
to
b8528db
Compare
b8528db
to
8f9ddb8
Compare
8f9ddb8
to
29041b6
Compare
@luca-landa the PR is almost ready now, thanks for the work you've done so far! There are still a couple of cosmetic issues raised by Hound, and this merge commit that should be dealt with. |
ec79d5b
to
ca6e770
Compare
@spaghetticode I'm sorry I completely lost track of this PR 😅 it should be fixed now |
After switching payment service provider, previous payment method records still exist in spree_payment_methods table, referencing an unexisting class for STI. This generates ActiveRecord::SubclassNotFound errors while retrieving the records from the database. This commit adds a task that resets the type of unsupported payment methods to Spree::PaymentMethod, and records the old actual type in a new "type_before_removal" field. This allows to keep previous orders which still reference these unsupported payment methods.
Show a simple error after retrieving payment methods no more supported, suggesting to run a specific rake task to fix the issue and without having to delete those payment methods.
ca6e770
to
a6a2d44
Compare
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.
LGTM, thanks Luca!
Hey @jarednorman, I think your concern was addressed 🙂 Is there anything else we need to tackle here? |
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.
No, I'm happy here.
PR solidusio#3837 added a rake task to deactivate payment method records that are no longer valid because of removing a payment method class. The task iterates over all payment method records and tries to constantize from its polymorphic type column. When that process returns a `NameError`, it assumes that the class is no longer present and proceeds to deactivate the record. Before this commit, `ActiveSupport::Dependencies.constantize` was used. However, the method was removed on Rails 7 [1], so our code raised a `NoMethodError`. As `NoMethodError` is a subclass of `NameError` [2], the deactivation logic was called for every record. As Rails recommends, we update the code to use `String#constantize` instead. [1] - https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#activesupport-dependencies-private-api-has-been-deleted [2] - https://ruby-doc.org/core-3.1.0/NoMethodError.html
PR #3837 added a rake task to deactivate payment method records that are no longer valid because of removing a payment method class. The task iterates over all payment method records and tries to constantize from its polymorphic type column. When that process returns a `NameError`, it assumes that the class is no longer present and proceeds to deactivate the record. Before this commit, `ActiveSupport::Dependencies.constantize` was used. However, the method was removed on Rails 7 [1], so our code raised a `NoMethodError`. As `NoMethodError` is a subclass of `NameError` [2], the deactivation logic was called for every record. As Rails recommends, we update the code to use `String#constantize` instead. [1] - https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#activesupport-dependencies-private-api-has-been-deleted [2] - https://ruby-doc.org/core-3.1.0/NoMethodError.html
Improve payment service providers switching errors
PR #3837 added a rake task to deactivate payment method records that are no longer valid because of removing a payment method class. The task iterates over all payment method records and tries to constantize from its polymorphic type column. When that process returns a `NameError`, it assumes that the class is no longer present and proceeds to deactivate the record. Before this commit, `ActiveSupport::Dependencies.constantize` was used. However, the method was removed on Rails 7 [1], so our code raised a `NoMethodError`. As `NoMethodError` is a subclass of `NameError` [2], the deactivation logic was called for every record. As Rails recommends, we update the code to use `String#constantize` instead. [1] - https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#activesupport-dependencies-private-api-has-been-deleted [2] - https://ruby-doc.org/core-3.1.0/NoMethodError.html
PR #3837 added a rake task to deactivate payment method records that are no longer valid because of removing a payment method class. The task iterates over all payment method records and tries to constantize from its polymorphic type column. When that process returns a `NameError`, it assumes that the class is no longer present and proceeds to deactivate the record. Before this commit, `ActiveSupport::Dependencies.constantize` was used. However, the method was removed on Rails 7 [1], so our code raised a `NoMethodError`. As `NoMethodError` is a subclass of `NameError` [2], the deactivation logic was called for every record. As Rails recommends, we update the code to use `String#constantize` instead. [1] - https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#activesupport-dependencies-private-api-has-been-deleted [2] - https://ruby-doc.org/core-3.1.0/NoMethodError.html
PR #3837 added a rake task to deactivate payment method records that are no longer valid because of removing a payment method class. The task iterates over all payment method records and tries to constantize from its polymorphic type column. When that process returns a `NameError`, it assumes that the class is no longer present and proceeds to deactivate the record. Before this commit, `ActiveSupport::Dependencies.constantize` was used. However, the method was removed on Rails 7 [1], so our code raised a `NoMethodError`. As `NoMethodError` is a subclass of `NameError` [2], the deactivation logic was called for every record. As Rails recommends, we update the code to use `String#constantize` instead. [1] - https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#activesupport-dependencies-private-api-has-been-deleted [2] - https://ruby-doc.org/core-3.1.0/NoMethodError.html
PR #3837 added a rake task to deactivate payment method records that are no longer valid because of removing a payment method class. The task iterates over all payment method records and tries to constantize from its polymorphic type column. When that process returns a `NameError`, it assumes that the class is no longer present and proceeds to deactivate the record. Before this commit, `ActiveSupport::Dependencies.constantize` was used. However, the method was removed on Rails 7 [1], so our code raised a `NoMethodError`. As `NoMethodError` is a subclass of `NameError` [2], the deactivation logic was called for every record. As Rails recommends, we update the code to use `String#constantize` instead. [1] - https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#activesupport-dependencies-private-api-has-been-deleted [2] - https://ruby-doc.org/core-3.1.0/NoMethodError.html
PR #3837 added a rake task to deactivate payment method records that are no longer valid because of removing a payment method class. The task iterates over all payment method records and tries to constantize from its polymorphic type column. When that process returns a `NameError`, it assumes that the class is no longer present and proceeds to deactivate the record. Before this commit, `ActiveSupport::Dependencies.constantize` was used. However, the method was removed on Rails 7 [1], so our code raised a `NoMethodError`. As `NoMethodError` is a subclass of `NameError` [2], the deactivation logic was called for every record. As Rails recommends, we update the code to use `String#constantize` instead. [1] - https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#activesupport-dependencies-private-api-has-been-deleted [2] - https://ruby-doc.org/core-3.1.0/NoMethodError.html
PR #3837 added a rake task to deactivate payment method records that are no longer valid because of removing a payment method class. The task iterates over all payment method records and tries to constantize from its polymorphic type column. When that process returns a `NameError`, it assumes that the class is no longer present and proceeds to deactivate the record. Before this commit, `ActiveSupport::Dependencies.constantize` was used. However, the method was removed on Rails 7 [1], so our code raised a `NoMethodError`. As `NoMethodError` is a subclass of `NameError` [2], the deactivation logic was called for every record. As Rails recommends, we update the code to use `String#constantize` instead. [1] - https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#activesupport-dependencies-private-api-has-been-deleted [2] - https://ruby-doc.org/core-3.1.0/NoMethodError.html
In the doc printed when it's needed, we had a typo, probably due to some back and forth on the PR that introduced the change. See #3837
Description
This PR is a solution for #3802.
Since old payment methods can't just be deleted after switching payment service provider, I provided a script to reset their
type
to a defaultSpree::PaymentMethod
, to avoid breaking Single Table Inheritance while buildingActiveRecord
instances.I added a
type_before_removal
field which will store the actualtype
value when the script is run.Also, the script sets
active
,available_to_admin
andavailable_to_users
flags to false.Moreover, I replaced the typical
ActiveRecord::SubclassNotFound
with a more meaningful error, which should save time to developers facing this issue and points them to the script.If I got something wrong please tell me, this was my first experience with the project :)
Checklist: