Asana / python-asana

Official Python client library for the Asana API v1
MIT License
299 stars 103 forks source link

Unable to paginate portfolio items #124

Closed mckibbenc closed 3 years ago

mckibbenc commented 3 years ago

When attempting to iterate over a collection of portfolio items, I get the following error:

2021-01-26 01:34:19,841 [m2a_integration] Traceback (most recent call last): File "src/integration.py", line 1053, in main() File "src/integration.py", line 1007, in main updatePortfolioProjects(asana_client, portfolios, projects, finished_projects) File "src/integration.py", line 591, in updatePortfolioProjects all_portfolio_projects[portfolio_name] = getPortfolioProjects(asana_client, portfolio_value["gid"]) File "src/integration.py", line 208, in getPortfolioProjects for portfolio_project in portfolio_projects: File "/lib/python3.7/site-packages/asana/page_iterator.py", line 58, in items for page in self: File "/lib/python3.7/site-packages/asana/page_iterator.py", line 43, in next result = self.get_next() File "/lib/python3.7/site-packages/asana/page_iterator.py", line 73, in get_next return self.client.get(self.path, self.query, self.options) File "/lib/python3.7/site-packages/asana/client.py", line 171, in get return self.request('get', path, params=query, options) File "/lib/python3.7/site-packages/asana/client.py", line 103, in request raise e File "/lib/python3.7/site-packages/asana/client.py", line 89, in request raise STATUS_MAPresponse.status_code asana.error.ServerError: Server Error: Oops! An unexpected error occurred while processing this request. The input may have contained something the server did not know how to handle. For more help, please contact api-support@asana.com and include the error phrase from this response.

Here is the relevant code block that triggers this error:

portfolio_projects = asana_client.portfolios.get_items(portfolio_id, fields="gid,name")
    for portfolio_project in portfolio_projects:
        asana_portfolio_projects_dict[portfolio_project["name"]] = {
            "gid": portfolio_project["gid"]
        }

The above error only triggers when I attempt to iterate over a portfolio that has more than 50 items. Changing page size to 100 fixes this issue in the short term, but I need to get pagination working so I can handle more than 100 items.

I'm using the asana python client version 0.10.3 with Python 3.8

rossgrambo-zz commented 3 years ago

Hello @mckibbenc !

We just updated something in the API for the portfolio endpoint. Did this error just start happening? Or is this new code?

mckibbenc commented 3 years ago

This just started happening. I have been using this endpoint for the past year without any issue until just a couple days ago.

rossgrambo-zz commented 3 years ago

Alright it looks like the API team was already aware of it. They just deployed a fix. Let me know if things still aren't working for you!