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

Split the with_deferred_parent_expiration and with_deferred_parent_expiration #578

Merged
merged 3 commits into from
Oct 22, 2024

Conversation

drinkbeer
Copy link
Contributor

@drinkbeer drinkbeer commented Oct 11, 2024

  • Split the with_deferred_parent_expiration and with_deferred_parent_expiration to ensure the API is backward compatible
  • Add a deprecation message for with_deferred_parent_expiration
  • Restore all the original unit tests of with_deferred_parent_expiration, to ensure the behaviour of it is not changed

Deprecation message (tested with ActiveRecord 7.0 and 7.2):
image

@drinkbeer drinkbeer requested review from Stivaros and a team October 11, 2024 17:49
@drinkbeer
Copy link
Contributor Author

Tested in my mac with the following version of activerecord gem:

  • activerecord-7.2.0
  • activerecord-7.0.8.5
  • activerecord-7.2.1.1
  • activerecord in main branch

All is ✅ .

@drinkbeer drinkbeer marked this pull request as ready for review October 21, 2024 19:46
CHANGELOG.md Show resolved Hide resolved
@@ -225,6 +269,10 @@ def fetch_multi(*keys)
def with_deferred_expiration
raise NestedDeferredCacheExpirationBlockError if Thread.current[:idc_deferred_expiration]

if Thread.current[:idc_deferred_parent_expiration]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we deprecating here? Shouldn't we raise if they are both used? Ie with a nested deffered exception?

raise NestedDeferredParentBlockError if Thread.current[:idc_deferred_parent_expiration]

if Thread.current[:idc_deferred_expiration]
deprecator.deprecation_warning("`with_deferred_parent_expiration`")
Copy link
Contributor

Choose a reason for hiding this comment

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

This should raise, not just emit a deprecation. The two are not compatible right?

Copy link
Contributor

Choose a reason for hiding this comment

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

We should just always emit this deprecation. It shouldn't be blocked by the deferred expiration flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just a warning, so will not block. We don't want to raise errors here, because we want the two methods are compatible.

The with_deferred_expiration has already covered with_deferred_parent_expiration.

  • parent deferred expiration: supported by both.
  • child deferred expiration: only supported by with_deferred_parent_expiration.
  • attribute deferred expiration: only supported by with_deferred_parent_expiration.

Copy link
Contributor Author

@drinkbeer drinkbeer Oct 21, 2024

Choose a reason for hiding this comment

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

The two methods can be nested and used together as they are compatible. We don't need to raise and fail if they are used together. The warning here is just to cover the case in this unit test: https://github.com/Shopify/identity_cache/pull/578/files#diff-a5e1bbc9f7c7519a1e9bd0e04064c349f39bf6a6a4d029651461b87ef81dde1eR258-R290

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there are two separate things here.

Regarding the incompatibility, I had the same concern, @grcooper. @drinkbeer and I paired on it and the nesting should be compatible, as also evidenced by the tests.

If there is a scenario we are concerned about we should write a test for it.

However, I think we should just be deprecating the use of this method in all cases (rather than the gated warning) as we want to progress to a V2 where we remove this method and just have people use .with_deferred_expiration.

So:

  • Always fire the deprecation notice for .with_deferred_parent_expiration
  • Maintain compatibility between the two APIs for now
  • Seek to remove this method as a breaking change at the earliest convenience

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok, I was thinking that they were not compatible. It looks like that test proves that they are compatible though and are not duplicating work 👍

@drinkbeer drinkbeer requested a review from grcooper October 21, 2024 20:31
Copy link
Contributor

@Stivaros Stivaros left a comment

Choose a reason for hiding this comment

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

Two comments that I think need actioning but nothing blocking 👍

Thank you for your hard work on this! ❤️

CHANGELOG.md Show resolved Hide resolved
raise NestedDeferredParentBlockError if Thread.current[:idc_deferred_parent_expiration]

if Thread.current[:idc_deferred_expiration]
deprecator.deprecation_warning("`with_deferred_parent_expiration`")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there are two separate things here.

Regarding the incompatibility, I had the same concern, @grcooper. @drinkbeer and I paired on it and the nesting should be compatible, as also evidenced by the tests.

If there is a scenario we are concerned about we should write a test for it.

However, I think we should just be deprecating the use of this method in all cases (rather than the gated warning) as we want to progress to a V2 where we remove this method and just have people use .with_deferred_expiration.

So:

  • Always fire the deprecation notice for .with_deferred_parent_expiration
  • Maintain compatibility between the two APIs for now
  • Seek to remove this method as a breaking change at the earliest convenience

Thoughts?

@grcooper
Copy link
Contributor

So:

Always fire the deprecation notice for .with_deferred_parent_expiration
Maintain compatibility between the two APIs for now
Seek to remove this method as a breaking change at the earliest convenience

Yah all of these points make sense to me 👍 I think always firing the deprecation notice would be good.

@drinkbeer drinkbeer merged commit 512764c into main Oct 22, 2024
5 checks passed
@drinkbeer drinkbeer deleted the jchen/split_parent_and_attributes_calls branch October 22, 2024 16:49
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.

3 participants