-
Notifications
You must be signed in to change notification settings - Fork 338
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
Fix PaywallEvents failing to deserialize #4520
Conversation
@@ -52,6 +52,34 @@ class PaywallEventSerializerTests: TestCase { | |||
expect(try event.encodeAndDecode()) == event | |||
} | |||
|
|||
func testEncodingBooleans() throws { |
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.
This fails in main
@@ -57,6 +57,33 @@ class PaywallEventsRequestTests: TestCase { | |||
assertSnapshot(matching: requestEvent, as: .formattedJson) | |||
} | |||
|
|||
func testCanInitFromDeserializedEvent() throws { |
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.
This fails in main. It's very similar to the other test, but it uses the EventsRequest.PaywallEvent(storedEvent:
initializer
@@ -66,7 +93,7 @@ class PaywallEventsRequestTests: TestCase { | |||
|
|||
private static let eventData: PaywallEvent.Data = .init( | |||
offeringIdentifier: "offering", | |||
paywallRevision: 5, | |||
paywallRevision: 0, |
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.
Change this to 0 since the decoder will have more trouble understanding it's an int and not a boolean
@@ -16,17 +16,16 @@ import Foundation | |||
/// Contains the necessary information for storing and sending events. | |||
struct StoredEvent { | |||
|
|||
private(set) var encodedEvent: AnyEncodable | |||
private(set) var encodedEvent: String |
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 decided to just store a string since it's just simpler, easier to understand and less bug prone
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.
Just for my understanding, does this change what the event looks like on disk? Wasn't it a string before?
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.
You're correct. It will be an encoded String though. Before it was an encoded dictionary which fails to decode as a String.
Example of before:
{"user_id":"$RCAnonymousID:5b2741807e1b4d939767b3d2ed4fbe9a","event":{"impression":{"_0":{"date":"2024-11-25T20:30:42Z","id":"0B593A2F-1553-41DC-9CFD-16A12D89C418"},"_1":{"offering_identifier":"offering","locale_identifier":"en_ES","session_identifier":"2E57D4B8-55E3-4B24-93B1-55EA5F46DE38","display_mode":"full_screen","dark_mode":false,"paywall_revision":0}}}}
Example of after:
{"feature":"paywalls","event":"{\"impression\":{\"_1\":{\"paywall_revision\":0,\"session_identifier\":\"AF96931D-2A9F-4BA3-BBD2-DB255F2DCF0F\",\"display_mode\":\"full_screen\",\"offering_identifier\":\"offering\",\"locale_identifier\":\"en_ES\",\"dark_mode\":false},\"_0\":{\"date\":\"2024-11-26T10:20:23Z\",\"id\":\"BD9897AE-2C6D-4824-A9FE-7DBF20B8E313\"}}}","user_id":"$RCAnonymousID:5b2741807e1b4d939767b3d2ed4fbe9a"}
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.
Alright thanks! So does this mean we won't be able to decode whatever events were already stored on disk (encoded with the previous version)?
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.
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.
Sweet, thanks for explaining!
return lhs.userID == rhs.userID && | ||
lhs.feature == rhs.feature && | ||
(lhsValue as NSDictionary).isEqual(to: rhsValue) | ||
return NSDictionary(dictionary: lhsDict).isEqual(rhsDict) |
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.
This is mainly used for tests assertions so not super worried about it decoding events. It's the only way to be honest, otherwise the order of the keys in the JSON would make it fail
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.
Good to have this fixed! Just a question.
@@ -16,17 +16,16 @@ import Foundation | |||
/// Contains the necessary information for storing and sending events. | |||
struct StoredEvent { | |||
|
|||
private(set) var encodedEvent: AnyEncodable | |||
private(set) var encodedEvent: String |
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.
Just for my understanding, does this change what the event looks like on disk? Wasn't it a string before?
It looks like
PaywallEvents
are broken since 5.8.0The issue is that paywall_revision is being serialized as a boolean in the file, because AnyEncodable is interpreting it the 0 as a boolean