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

[MBL-960] Fix crash by using default hashing and equality for the config #1850

Merged
merged 2 commits into from Sep 6, 2023

Conversation

ifosli
Copy link
Contributor

@ifosli ifosli commented Sep 5, 2023

📲 What

Update the date formatter to conform to Hashable and Equatable by default instead of having custom implementations. This has the effect of also relying on the dateFormat when comparing two DateFormatterConfig objects.

Also add a test that fails without these changes and passes now that the caching is fixed.

🤔 Why

Currently, when the dateFormat is ignored in comparisons, when we try to parse a different date format, we fetch a cached one expecting a different format, leading to a crash. This happens any time we try to create a formatter for a config that has a different date format but is otherwise identical to a formatter that's already been cached. Specifically, this happens when we show the creator tools deprecation banner and also show credit card expiration dates without killing the app in-between.

👀 See

JIRA ticket

✅ Acceptance criteria

  • Crash no longer repros

@ifosli ifosli added this to the release-5.11.0 milestone Sep 5, 2023
@ifosli ifosli self-assigned this Sep 5, 2023
@ifosli ifosli added the bug label Sep 5, 2023
@codecov
Copy link

codecov bot commented Sep 5, 2023

Codecov Report

Merging #1850 (9c50513) into main (16567fe) will increase coverage by 0.00%.
Report is 1 commits behind head on main.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1850   +/-   ##
=======================================
  Coverage   84.59%   84.59%           
=======================================
  Files        1276     1276           
  Lines      116026   116017    -9     
  Branches    30892    30888    -4     
=======================================
- Hits        98155    98149    -6     
+ Misses      16788    16786    -2     
+ Partials     1083     1082    -1     
Files Changed Coverage Δ
Library/Format.swift 88.29% <ø> (-0.49%) ⬇️
Library/FormatTests.swift 98.40% <100.00%> (+0.01%) ⬆️

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@msadoon msadoon left a comment

Choose a reason for hiding this comment

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

Yea nice clean up.

@@ -403,7 +403,7 @@ public enum Format {

public let defaultThresholdInDays = 30 // days

internal struct DateFormatterConfig {
internal struct DateFormatterConfig: Hashable, Equatable {
Copy link
Contributor

@msadoon msadoon Sep 6, 2023

Choose a reason for hiding this comment

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

Cool, yea let's do this - according to the documentation - Hashable conformance requires Equatable, so you probably only need Hashable.
https://developer.apple.com/documentation/swift/hashable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, I'll delete the explicit Equatable. Thanks!

@ifosli ifosli merged commit 9d9566b into main Sep 6, 2023
7 checks passed
@ifosli ifosli deleted the dateFormatCrash branch September 6, 2023 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants