question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RDT shortcut approach doesn't work for multi-page response

See original GitHub issue

Describe the bug When using the Orders.get_order call and handing through a RestrictedResource and getting a response that spans multiple pages, the RDT is only being used for the first page. This means that the first page will have the restricted data fields, but they will be silently dropped from all following pages in the same request (loaded via next_token).

The first page will take this branch in sp_api/api/orders/orders.py.get_orders:

if 'RestrictedResources' in kwargs:
   return self._access_restricted(kwargs)

and will get an RDT via:

self.restricted_data_token = token['restrictedDataToken']
r = self._request(kwargs.pop('original_path'), params={**kwargs})
self.restricted_data_token = None

but it will clear the RDT after the API call again. For the next page, there are no RestrictedResources in the kwargs, just the next_token and hence the call will be made without RDT (doesn’t take the ifbranch, leading to the API to return the orders WITHOUT the restricted data:

return self._request(fill_query_params(kwargs.pop('path'), order_id), params={**kwargs}, add_marketplace=False)

There is no error message, this fails silently and can only be seen in the resulting data.

To Reproduce Load a get_order request that spans multiple pages (more than 100 rows) and call it with the @load_all_pages decorator. Check the restricted data in the first page and subsequent pages. Use the shortcut call as outlined in the documentation.

orders = Orders().get_orders(
    RestrictedResources=['buyerInfo', 'shippingAddress'],
    LastUpdatedAfter=(datetime.utcnow() - timedelta(days=1)).isoformat()
)

Expected behavior

The RDT should carry through to all subsequent pages and these should also return the restricted data.

Additional context

Workaround is to manually get an RDT and to hand it over in the creation of the Order instance or set the restricted_data_token instance variable after instantiation.

Orders(restricted_data_token='<token>').get_orders(CreatedAfter=(datetime.utcnow() - timedelta(days=7)).isoformat())

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
saleweavercommented, Apr 2, 2022

@chadsaun @dannyrohde I’ve pushed a little change to make this work, can you have a look if it works for you please. Not released yet, please pull from master. Usage is using with:

with Orders() as client:
    r = client.get_orders(RestrictedResources=['buyerInfo', 'shippingAddress'], LastUpdatedAfter=(datetime.now() - timedelta(days=30)).isoformat())
    log.info(r)
    x = client.get_orders(NextToken=r.next_token)
    log.info(x)
# no more restricted resources here.
log.info(client.get_orders(NextToken=r.next_token))

https://github.com/saleweaver/python-amazon-sp-api/commit/e806506995a3b5c0a2d64cafdbfcbf321cd65bfd I think I’ll change it to with Orders(restricted_resources=['buyerInfo', 'shippingAddress']) as client - what do you think?

1reaction
dannyrohdecommented, Mar 4, 2022

Yes, that makes sense. I’m quite busy atm, but I hope to have time to take a look on the weekend. If you find something that works well, please comment or create a PR 👍 .

Thanks for your efforts. Also wanted to say that I really appreciate the time and effort you put into this package. It really helps me a lot on my current project and I enjoy learning from reading the code.

I’ll have a look at the debugger again and see if there’s anything I can contribute to.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remote Desktop Services Shortcut Keys - Win32 apps
If these shortcuts don't work, or the keys aren't available, you can try the following alternative: Press CTRL+ALT+HOME, TAB, TAB, TAB, TAB, TAB...
Read more >
Troubleshooting problems with keyboard shortcuts | IntelliJ ...
First of all, check whether the shortcut should work as you expect. It may be obvious for shortcuts like Ctrl+C and Ctrl+V ,...
Read more >
Eclipse shortcut keys are not working suddenly in Windows
Eclipse shortcut keys are not working suddenly in Windows. Even basic needed shortcut keys like 'ctrl + F' and 'ctrl + c' don't...
Read more >
Change a conflicting keyboard shortcut on Mac
On your Mac, choose Apple menu > System settings, then click Keyboard in the sidebar.
Read more >
Creating and handling shortcuts
Discover the simple process of creating and handling shortcuts for apps, leaving you free to peruse the range of potential responses.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found