RDT shortcut approach doesn't work for multi-page response
See original GitHub issueDescribe 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 if
branch, 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:
- Created 2 years ago
- Comments:6 (3 by maintainers)
@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
: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?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.