Different Date Logic between Order Count and Order Find in Shopify API

rbnali
Excursionist
16 1 1

Hi,

I noticed some discrepancies in the number of returned results between Order.find and Order.count in the Shopify API. Local timezone is taken into account with Order.find but not with Order.count.

  • Order.count(created_at_min=my_date) will return the number of orders created after `my_date` without taking the timezone into account.
  • If I take Order.find(created_at_min=my_date) and add all results from pagination, I will have all orders created after `my_date` with timezone taken into account.

We end up with different numbers of orders even though the setup is exactly the same.

Is that expected behavior?

- `shopify_python_api` version: 8.1.0
- `pyactiveresource` version: 2.2.0
- Shopify API version used: 2020-10

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

If you search the forum you will see similar issues raised. From what I recall querying for orders can provide unexpected results when narrowing down to timestamps. It seems that the API service pretty much ignores the time and just assesses the date. If you try similar queries through the GraphQL API (versus the REST API) I'm wondering if this issue is consistent there. Also, perhaps try an older API version...  

0 Likes
rbnali
Excursionist
16 1 1

Thanks for the additional context @Greg_Kujawa.

I did some additional testing and it seems that the discrepancy between Order.find and Order.count only appears when the timezone is not specified.

I've created an issue on the shopify api python library repo (https://github.com/Shopify/shopify_python_api/issues/444) but it might be worth creating an issue directly assigned to the REST API. Do you know where such issues are usually tracked?

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

Interesting observations. I'm hopeful that someone from Shopify will be able to pick this up, replicate it, and push it for a fix. Definitely some gotchas when it comes to this.  

0 Likes
syf_
Shopify Staff
Shopify Staff
89 20 15

Hi @rbnali,

Thanks for reporting the discrepancy noted between Order.find and the Order.count. I've done some initial testing using the REST Admin, and I haven't been able to reproduce the said behaviour. Could you confirm you see the same discrepancy when you use the REST Admin? If you do, could you kindly provide the x-request-id's of the two calls made, and I'll be able to look into this more.

 

Thanks,

Seth.

syf_ | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
rbnali
Excursionist
16 1 1

Hi @syf_ ,

Sorry for the late response.

I confirm I see a discrepancy on the REST Admin API as well.

Examples:

  • X-Request-ID with the /admin/api/2021-01/orders/count.json endpoint: `b866e959-6755-49e2-91dc-03a61e8e3443`
  • X-Request-ID with the /admin/api/2021-01/orders.json endpoint: `15b36711-67f9-4318-91eb-0822b62831db`

In that case we have count.json gives 25 and orders.json gives 0 order even though the parameters are the same (?status=any&created_at_min=2021-01-13T23:00:00:00).

Tagging @paulomarg as well who was active on the github thread.

0 Likes
syf_
Shopify Staff
Shopify Staff
89 20 15

Hi @rbnali,

Thanks for providing me with the examples.

After doing some investigation, we've been able to identify what may be causing this issue. Our devs have been made aware, and they are currently looking into the issue. I'm unable to give a timeline for this, but I'd update you immediately I hear anything back.

In the meantime, a current workaround is to use UTC time and not your local time for the /orders.json endpoint. I know this is an inconvenience and I assure you our dev team is working to fix this issue. 

Let me know if the workaround I suggested works, or you have any additional questions related to this issue.

Thanks,
Seth.

syf_ | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Greg_Kujawa
Shopify Partner
1016 83 237

I always find it more consistent and less quirks to remember by defaulting the online shop's time zone to UTC, as well as defaulting to that for all of my own code. Especially if I have client-side code and the users could obviously be in different time zones. In terms of and JWT's for my own hosted apps, for Shopify queries, for reporting, etc. 

0 Likes