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

Fix for date deserialization when JSON contains dates lower than DateTime.MinValue #804

Merged
merged 1 commit into from
Nov 3, 2022

Conversation

clement911
Copy link
Collaborator

Fixes #803

…ed it globally to all date properties

-Simplified the JSON serialization logic
@clement911
Copy link
Collaborator Author

@nozzlegear @davidkdb here is my PR to fix #803
I've made a simple fix for now but this should open up more flexibility in the future for the host application to be able to subscribe to an event when invalid dates are detected and apply custom logic.

@clement911
Copy link
Collaborator Author

@nozzlegear I'm bumping this up for your attention as this seems to be occurring again today, i.e. Shopify is sending webhooks with invalid dates.
Without this fix, I have to manually edited webhook JSONs to fix the invalid dates.
Are you able to push a release for this fix?

@nozzlegear nozzlegear merged commit 63570bf into nozzlegear:master Nov 3, 2022
@nozzlegear nozzlegear added bug missing or invalid properties upstream An issue with Shopify's implementation and not necessarily this package. labels Nov 3, 2022
@nozzlegear
Copy link
Owner

Thanks for the fix @clement911! Once the unit tests finish running I'll be able to publish to nuget, but I need to step out of the house in a few minutes. I'll set a reminder to publish this once I'm back, but feel free to ping me again if it seems like I forgot!

@clement911
Copy link
Collaborator Author

That's much appreciated @nozzlegear
I think the tests are all green: https://github.com/nozzlegear/ShopifySharp/actions/runs/3389537167

@nozzlegear
Copy link
Owner

Published in 5.18.7 on nuget! Thanks a ton for investigating and debugging. 🕵️

@clement911
Copy link
Collaborator Author

Awesome. Thanks for the quick release!

@davidkdb
Copy link

davidkdb commented Nov 4, 2022

It's not published yet here?

@nozzlegear
Copy link
Owner

@davidkdb There's a little bit of a delay between when the package gets published to nuget and when nuget indexes the new version and makes it available for search/download. Sometimes it can take up to an hour.

@davidkdb
Copy link

davidkdb commented Nov 5, 2022

Still not available for download....

@clement911
Copy link
Collaborator Author

https://www.nuget.org/packages/ShopifySharp/5.18.7
Isn't this what you need?

@davidkdb
Copy link

davidkdb commented Nov 6, 2022

Thank you :-)

It was just not visible on: https://github.com/nozzlegear/ShopifySharp

@davidkdb
Copy link

davidkdb commented Nov 6, 2022

BTW: After the fix, accepts_marketing_updated_at seems to not work anymore with invalid null date. So what was working, is not working anymore.

@clement911
Copy link
Collaborator Author

Can you explain in more detail what is not working? Or even better if you can create a test that shows the issue?

@davidkdb
Copy link

davidkdb commented Nov 7, 2022

This data is received from the orders updated or order created webhook. So this is the order data.

We just do:

ShopifySharp.Order orderData = null;
                            try
                            {
                                orderData = JsonConvert.DeserializeObject<ShopifySharp.Order>(bodyText);
                            }

I have removed most info, and made some adjustments in id's for security and privacy reasons. As you can see the accepts_marketing_updated_at has an invalid date, and the code fails at the DeserializeObject pointing to accepts_marketing_updated_at

{
    "id": 1010101,
    "customer":
    {
        "id": 01010101,
        "accepts_marketing_updated_at": "0000-12-31T18:09:24-05:50",
        "marketing_opt_in_level": "unknown",
        "tax_exemptions": [],
        "email_marketing_consent":
        {
            "state": "subscribed",
            "opt_in_level": "unknown",
            "consent_updated_at": null
        },
        "sms_marketing_consent":
        {
            "state": "subscribed",
            "opt_in_level": "single_opt_in",
            "consent_updated_at": "2021-07-09T19:31:42-05:00",
            "consent_collected_from": "OTHER"
        },
        "admin_graphql_api_id": "gid://shopify/Customer/01010101"
    },
    "discount_applications": [],
    "fulfillments": []
}

@clement911
Copy link
Collaborator Author

Please try to deserialize as follows:

var order = ShopifySharp.Infrastructure.Serializer.Deserialize<Order>(json);

@clement911 clement911 deleted the date-deserialization-fix branch November 8, 2022 00:12
@clement911
Copy link
Collaborator Author

@davidkdb did that fix your issue?

I also just pushed a new PR to handle invalid dates returned by the API (as opposed to invalid dates in webhooks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug missing or invalid properties upstream An issue with Shopify's implementation and not necessarily this package.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Critical: Bug in date handling
3 participants