Up until last week I could correctly iterate list() from Advisor Management Client: client.recommendation.list(). Now it acts like a while loop, i have no way to stop it other than control-c. One of my coworkers confirmed the same behavior on her laptop. Not sure what's going on, other clients (subscription, for instance) are iterating correctly with expected behavior.
from azure.common.credentials import get_azure_cli_credentials
from azure.mgmt.advisor import AdvisorManagementClient
from azure.mgmt.subscription import SubscriptionClient
creds, subscriptionID = get_azure_cli_credentials()
sClient = SubscriptionClient(creds)
aClient = AdvisorManagementClient(creds, "my subscription id")
for recommendation in aClient.recommendations.list():
print(recommendation.impacted_value)
It hangs from the cli list command--used to work too:
az account set --subscription mysubscription
az advisor recommendation list
Hi @rominoff
Could you post a few logs from the CLI in --debug mode? I guess if you have an infinite loop you will see the same call done again and again. I would be curious to see if this is something like "page X" in loop, or "page X to page X+1 to page X to page X+1" etc. (two pages in cycle).
@Prasanna-Padmanabhan for advice.
Yes, please, logs will help. I am not aware of any such issue nor have there been any updates to the client, so I would be very interested to dig into this.
Hi!
ok, changed the code a little bit to capture the end of the list and rolling over to the beginning of the list, here's the guts of the code:
From the debug code i could see there were 47 entries so i started capturing on 46--to save iteration cycles. The first entry returned was: recommendation.impacted_value: Standard_DS1_v2 virtual machines in eastus, the second time through it was again in the code.
for recommendation in aClient.recommendations.list(raw=True):
reccount += 1
print(str(reccount))
if reccount == 46:
pdb.set_trace()
print(recommendation.impacted_value)
-> print(recommendation.impacted_value)
(Pdb) s
defender1
/Users/bbell/testrecommendation.py(33)
()
-> for recommendation in aClient.recommendations.list(raw=True):
(Pdb) s
--Call--
/usr/local/lib/python3.7/site-packages/msrest/paging.py(133)__next__()
-> def __next__(self):
(Pdb) n
/usr/local/lib/python3.7/site-packages/msrest/paging.py(138)__next__()
-> if self.current_page and self._current_page_iter_index < len(self.current_page):
(Pdb) p self._current_page_iter_index
46
(Pdb) p len(self.current_page)
47
(Pdb) n
/usr/local/lib/python3.7/site-packages/msrest/paging.py(139)__next__()
-> response = self.current_page[self._current_page_iter_index]
(Pdb) n
/usr/local/lib/python3.7/site-packages/msrest/paging.py(140)__next__()
-> self._current_page_iter_index += 1
(Pdb) n
/usr/local/lib/python3.7/site-packages/msrest/paging.py(141)__next__()
-> return response
(Pdb) n
--Return--
/usr/local/lib/python3.7/site-packages/msrest/paging.py(141)__next__()->
-> return response
(Pdb) n
/Users/bbell/testrecommendation.py(34)()
-> reccount += 1
(Pdb) n
/Users/bbell/testrecommendation.py(35)()
-> print(str(reccount))
(Pdb) n
47
/Users/bbell/testrecommendation.py(36)()
-> if reccount == 46:
(Pdb) n
/Users/bbell/testrecommendation.py(39)()
-> print(recommendation.impacted_value)
(Pdb) s
7f16c69f-410d-4463-b131-912e2572c245
/Users/bbell/testrecommendation.py(33)()
-> for recommendation in aClient.recommendations.list(raw=True):
(Pdb) s
--Call--
/usr/local/lib/python3.7/site-packages/msrest/paging.py(133)__next__()
-> def __next__(self):
(Pdb) n
/usr/local/lib/python3.7/site-packages/msrest/paging.py(138)__next__()
-> if self.current_page and self._current_page_iter_index < len(self.current_page):
(Pdb) p self._current_page_iter_index
47
(Pdb) p len(self.current_page)
47
(Pdb) n
/usr/local/lib/python3.7/site-packages/msrest/paging.py(143)__next__()
-> self.advance_page()
(Pdb) n
/usr/local/lib/python3.7/site-packages/msrest/paging.py(144)__next__()
-> return self.__next__()
(Pdb) n
--Return--
/usr/local/lib/python3.7/site-packages/msrest/paging.py(144)__next__()->
-> return self.__next__()
(Pdb) n
/Users/bbell/testrecommendation.py(34)()
-> reccount += 1
(Pdb) n
/Users/bbell/testrecommendation.py(35)()
-> print(str(reccount))
(Pdb) n
48
/Users/bbell/testrecommendation.py(36)()
-> if reccount == 46:
(Pdb) n
/Users/bbell/testrecommendation.py(39)()
-> print(recommendation.impacted_value)
(Pdb) s
Standard_DS1_v2 virtual machines in eastus
/Users/bbell/testrecommendation.py(33)()
-> for recommendation in aClient.recommendations.list(raw=True):
(Pdb) s
--Call--
/usr/local/lib/python3.7/site-packages/msrest/paging.py(133)__next__()
-> def __next__(self):
(Pdb) n
/usr/local/lib/python3.7/site-packages/msrest/paging.py(138)__next__()
-> if self.current_page and self._current_page_iter_index < len(self.current_page):
(Pdb) p self._current_page_iter_index
1
(Pdb) p len(self.current_page)
47
(Pdb)
Thanks for providing the details and apologies for the delay in responding. @mojayara is looking into this.
@lmazuel @iscai-msft Can you guys look into this issue?
Hi we've been looking into this issue and we've found that for recommendations paging, the next link the server returns is an empty string when it's done instead of a null string. In all other cases, the server returns a null string. Since it's not returning null, we keep paging leading to the infinite loop. Nothing in the Python side has changed, this change originated on the server side, @mojayara can you change it back to returning null? Thanks!
Please let me know once it is changed back, thanks for tracking this down
A fix is coming from the python team for this issue.
Great!
Update, a regression was introduced in our system which added this infinite looping. We have a fix rolled out this week.
Thanks @mojayara !
Thank you!!!
A fix is coming from the python team for this issue.
Hi @mojayara I'm running into the same issue, how can I fix it
Update, a regression was introduced in our system which added this infinite looping. We have a fix rolled out this week.
Has the fix rolled out @mojayara
Yes, the roll-out for the fix is in progress this week.
Yes, the roll-out for the fix is in progress for this week.
Yeah, I think its worked for me now, I was using the old version of azure-mgmt-advisor (1.0.1) I've upgrade the package to 2.0.1, and this time it worked, no looping :)
Thanks @mojayara
Most helpful comment
Yeah, I think its worked for me now, I was using the old version of azure-mgmt-advisor (1.0.1) I've upgrade the package to 2.0.1, and this time it worked, no looping :)
Thanks @mojayara