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

Introduce deprecation warning when using Spree::Refund#perform! callback #3181

Closed

Conversation

aitbw
Copy link
Contributor

@aitbw aitbw commented Apr 16, 2019

Description

This PR introduces a deprecation warning when relying on Spree::Refund#perform! implicitly (i.e.: calling it as a callback rather than calling it explicitly); aims to serve as a starting point for #1415

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)

This commit introduces a deprecation warning for Solidus-based stores
expecting `Spree::Refund#perform!` to be automatically executed

Neither Ruby nor Rails include a built-in way to define accessors with
default values; here, we define a method and a writer accessor with the
same name, so we can set a value or fallback to a default one

Serves as starting point for solidusio#1415
@kennyadsl
Copy link
Member

Thanks for this change! I think we should submit this change with #1415 commits as well since we would otherwise ship a deprecation warning without the code that does the "new thing". WDYT?

@aitbw
Copy link
Contributor Author

aitbw commented Apr 17, 2019

@kennyadsl, sounds good to me. Do you want me to rebase that PR and then add these commits or cherry pick them into this branch?

@kennyadsl
Copy link
Member

I think we can use this PR cherry-picking and close that one, thanks!

@aitbw
Copy link
Contributor Author

aitbw commented Apr 24, 2019

@kennyadsl, I noticed something while re-reading your first comment: if we include the changes proposed in #1415 alongside this PR, we'd render this warning useless as the callback would be removed prior to Solidus v3.0 (which I assume is not the intended) and we would not be giving the developers any previous notice that the #perform! callback is going to be removed.

What do you think?

@kennyadsl
Copy link
Member

I think that what we have to do is:

  • call perform explicitly after save (no more callbacks), always using the perform_after_creation=false attribute
  • provide a way to tell users that are saving the refund in their store to:
    • add the perform_after_creation=false attribute before save (or they will see the deprecation)
    • call .perfrom manually

In the next version released, we can safely deprecate perform_after_creation since we can assume all stores are calling .perform manually, and they no longer need to set perform_after_creation.

Does it make sense?

@aitbw
Copy link
Contributor Author

aitbw commented Apr 24, 2019

@kennyadsl, yes, that makes sense, but my concern is focused on the stores that rely on that callback to be performed automatically —would that change break their stores if we don't give them a previous warning?

@kennyadsl
Copy link
Member

If they don't set perform_after_creation=false the default is true and they should have the perform called, isn't it?

@aitbw
Copy link
Contributor Author

aitbw commented Apr 24, 2019

No, the perform_after_creation only serves to show the deprecation warning; the #perform! callback is completely removed from #1415

@kennyadsl kennyadsl added this to the 2.11 milestone May 22, 2020
kennyadsl added a commit to nebulab/solidus that referenced this pull request May 26, 2020
We can't just stop calling this callback or we are going to break
applications when it's defined code like:

  Spree::Refund.create(attrs: ...)

since it currently relies on also calling perform! as well.

With this code, the old behavior is still there but we are asking
users to update their code to transition to the new behavior, which
is something like:

  Spree::Refund.create(attrs: ..., perform_after_creation: false).perform!

The two extra callbacks are needed to:

- set_perform_after_creation_default: prints the deprecation message only
  when creating the instance, otherwise it will be printed also when
  calling perform! on a good instance. Also, it sets the deafult to
  true when the attribute is not passed, which means that code has not
  been updated.
- clear_perform_after_creation: this callback is needed to clean the
  instance, after this game ends, otherwise each call of perform! after
  the callbacks execution could not be executed if the instance was
  created with perform_after_creations: false.

Specs needed some seriuos refactor to reflect this new architecture but
they look cleaner now.

Co-Authoring the commit since the initial code has been taken from solidusio#3181.

Co-authored-by: Angel Perez <[email protected]>
kennyadsl added a commit to nebulab/solidus that referenced this pull request May 27, 2020
We can't just stop calling this callback or we are going to break
applications when it's defined code like:

  Spree::Refund.create(attrs: ...)

since it currently relies on also calling perform! as well.

With this code, the old behavior is still there but we are asking
users to update their code to transition to the new behavior, which
is something like:

  Spree::Refund.create(attrs: ..., perform_after_creation: false).perform!

The two extra callbacks are needed to:

- set_perform_after_creation_default: prints the deprecation message only
  when creating the instance, otherwise it will be printed also when
  calling perform! on a good instance. Also, it sets the deafult to
  true when the attribute is not passed, which means that code has not
  been updated.
- clear_perform_after_creation: this callback is needed to clean the
  instance, after this game ends, otherwise each call of perform! after
  the callbacks execution could not be executed if the instance was
  created with perform_after_creations: false.

Specs needed some seriuos refactor to reflect this new architecture but
they look cleaner now.

Co-Authoring the commit since the initial code has been taken from solidusio#3181.

Co-authored-by: Angel Perez <[email protected]>
kennyadsl added a commit to nebulab/solidus that referenced this pull request May 29, 2020
We can't just stop calling this callback or we are going to break
applications when it's defined code like:

  Spree::Refund.create(attrs: ...)

since it currently relies on also calling perform! as well.

With this code, the old behavior is still there but we are asking
users to update their code to transition to the new behavior, which
is something like:

  Spree::Refund.create(attrs: ..., perform_after_create: false).perform!

The two extra callbacks are needed to:

- set_perform_after_create_default: prints the deprecation message only
  when creating the instance, otherwise it will be printed also when
  calling perform! on a good instance. Also, it sets the deafult to
  true when the attribute is not passed, which means that code has not
  been updated yet.
- clear_perform_after_create: this callback is needed to clean the
  instance, after this process ends, otherwise each call of perform! after
  the callbacks execution could not be executed if the instance was
  created with perform_after_create: false.

Specs needed some seriuos refactor to reflect this new architecture but
they look cleaner now.

Co-Authoring the commit since the initial code has been taken from solidusio#3181.

Co-authored-by: Angel Perez <[email protected]>
kennyadsl added a commit to nebulab/solidus that referenced this pull request May 29, 2020
We can't just stop calling this callback or we are going to break
applications when it's defined code like:

  Spree::Refund.create(attrs: ...)

since it currently relies on also calling perform! as well.

With this code, the old behavior is still there but we are asking
users to update their code to transition to the new behavior, which
is something like:

  Spree::Refund.create(attrs: ..., perform_after_create: false).perform!

The two extra callbacks are needed to:

- set_perform_after_create_default: prints the deprecation message only
  when creating the instance, otherwise it will be printed also when
  calling perform! on a good instance. Also, it sets the deafult to
  true when the attribute is not passed, which means that code has not
  been updated yet.
- clear_perform_after_create: this callback is needed to clean the
  instance, after this process ends, otherwise each call of perform! after
  the callbacks execution could not be executed if the instance was
  created with perform_after_create: false.

Specs needed some seriuos refactor to reflect this new architecture but
they look cleaner now.

Co-Authoring the commit since the initial code has been taken from solidusio#3181.

Co-authored-by: Angel Perez <[email protected]>
@kennyadsl
Copy link
Member

Closed in favor of #3641

@kennyadsl kennyadsl closed this May 29, 2020
@aitbw aitbw deleted the aitbw/refund_callback_deprecation branch May 29, 2020 21:15
aldesantis pushed a commit to aldesantis/solidus that referenced this pull request Dec 28, 2020
We can't just stop calling this callback or we are going to break
applications when it's defined code like:

  Spree::Refund.create(attrs: ...)

since it currently relies on also calling perform! as well.

With this code, the old behavior is still there but we are asking
users to update their code to transition to the new behavior, which
is something like:

  Spree::Refund.create(attrs: ..., perform_after_create: false).perform!

The two extra callbacks are needed to:

- set_perform_after_create_default: prints the deprecation message only
  when creating the instance, otherwise it will be printed also when
  calling perform! on a good instance. Also, it sets the deafult to
  true when the attribute is not passed, which means that code has not
  been updated yet.
- clear_perform_after_create: this callback is needed to clean the
  instance, after this process ends, otherwise each call of perform! after
  the callbacks execution could not be executed if the instance was
  created with perform_after_create: false.

Specs needed some seriuos refactor to reflect this new architecture but
they look cleaner now.

Co-Authoring the commit since the initial code has been taken from solidusio#3181.

Co-authored-by: Angel Perez <[email protected]>
aldesantis pushed a commit to aldesantis/solidus that referenced this pull request Dec 28, 2020
We can't just stop calling this callback or we are going to break
applications when it's defined code like:

  Spree::Refund.create(attrs: ...)

since it currently relies on also calling perform! as well.

With this code, the old behavior is still there but we are asking
users to update their code to transition to the new behavior, which
is something like:

  Spree::Refund.create(attrs: ..., perform_after_create: false).perform!

The two extra callbacks are needed to:

- set_perform_after_create_default: prints the deprecation message only
  when creating the instance, otherwise it will be printed also when
  calling perform! on a good instance. Also, it sets the deafult to
  true when the attribute is not passed, which means that code has not
  been updated yet.
- clear_perform_after_create: this callback is needed to clean the
  instance, after this process ends, otherwise each call of perform! after
  the callbacks execution could not be executed if the instance was
  created with perform_after_create: false.

Specs needed some seriuos refactor to reflect this new architecture but
they look cleaner now.

Co-Authoring the commit since the initial code has been taken from solidusio#3181.

Co-authored-by: Angel Perez <[email protected]>
mamhoff pushed a commit to mamhoff/solidus that referenced this pull request Feb 1, 2021
We can't just stop calling this callback or we are going to break
applications when it's defined code like:

  Spree::Refund.create(attrs: ...)

since it currently relies on also calling perform! as well.

With this code, the old behavior is still there but we are asking
users to update their code to transition to the new behavior, which
is something like:

  Spree::Refund.create(attrs: ..., perform_after_create: false).perform!

The two extra callbacks are needed to:

- set_perform_after_create_default: prints the deprecation message only
  when creating the instance, otherwise it will be printed also when
  calling perform! on a good instance. Also, it sets the deafult to
  true when the attribute is not passed, which means that code has not
  been updated yet.
- clear_perform_after_create: this callback is needed to clean the
  instance, after this process ends, otherwise each call of perform! after
  the callbacks execution could not be executed if the instance was
  created with perform_after_create: false.

Specs needed some seriuos refactor to reflect this new architecture but
they look cleaner now.

Co-Authoring the commit since the initial code has been taken from solidusio#3181.

Co-authored-by: Angel Perez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants