-
Notifications
You must be signed in to change notification settings - Fork 3.4k
{Role} az role assignment create: Use RoleAssignmentExists error code to implement idempotence
#32027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{Role} az role assignment create: Use RoleAssignmentExists error code to implement idempotence
#32027
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -1332,7 +1332,7 @@ def _process_certificate(cli_ctx, years, app_start_date, app_end_date, cert, cre | |||||||
|
|
||||||||
|
|
||||||||
| def _error_caused_by_role_assignment_exists(ex): | ||||||||
| return getattr(ex, 'status_code', None) == 409 and 'role assignment already exists' in ex.message | ||||||||
| return getattr(ex, 'status_code', None) == 409 and ex.error.code == 'RoleAssignmentExists' | ||||||||
|
||||||||
| return getattr(ex, 'status_code', None) == 409 and ex.error.code == 'RoleAssignmentExists' | |
| error = getattr(ex, 'error', None) | |
| return getattr(ex, 'status_code', None) == 409 and error is not None and getattr(error, 'code', None) == 'RoleAssignmentExists' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zhoxing-ms, is it possible that ex.error is None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, if the type of ex must be HttpResponseError, ex.error is guaranteed to exist, since many old codes are directly used ex.error.code for HttpResponseError. And because if ex has status_code attribute, it should indicate that ex is HttpResponseError, so, I personally speculate that this usage should be safe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar bad pattern of relying on error message instead of error code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new code is indeed relying on error code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant, this line still relies on message:
if retry_time < retry_times and ' does not exist in the directory ' in ex.messageUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. I see your point. This PR only aims to use
RoleAssignmentExistserror code. I will inform the ARM owner fix this line. @zhoxing-msThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll take a look when I have time and fix it in other PR