-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[Key Vault] Revise administration models #19049
Conversation
sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_models.py
Outdated
Show resolved
Hide resolved
if error is None or error.code is None: | ||
self._error = None | ||
else: | ||
self._error = ODataV4Format(vars(error)) |
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.
Small but important detail here: ODataV4Format expects the inner error to be labeled as innererror
, but the error we get back labels it as inner_error
and doesn't get applied to the resulting ODataV4Format object. Does it make sense to edit the label to be innererror
, or would that be forcing a square peg into a round hole?
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.
ODataV4Format expects JSON deserialized to a dict but the Error class generated by autorest has already deserialized the JSON and Pythonified "innererror" to "inner_error". What do you get from error.as_dict()
? Also, ODataV4Format.innererror
should be a JSON dict as well--it's JSON dicts all the way down.
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.
error.as_dict()
gives the same dictionary as vars(dict)
-- we're still left with an inner_error
key 😕
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.
Can you use the key_transformer
argument to rename it?
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.
Okay nice, that does work with something like:
def my_key_transformer(key, attr_desc, value):
if key == "inner_error":
return ("innererror", value)
return (key, value)
for errors with no inner error (error.inner_error = None
) and errors with JSON dict inner errors (they get recursively renamed)
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.
It looks like something like this would work as well:
error.as_dict(key_transformer=lambda k, _, v: ("innererror", v) if k == "inner_error" else (k, v))
Closing, since other changes that affect these are being done in #19099. |
Resolves #13575 and resolves #18992.