From 9e44ff4d6b5a50bd9ce617dad13307fa6eb68e54 Mon Sep 17 00:00:00 2001 From: Calvin Chan Date: Wed, 23 Mar 2022 11:57:58 -0700 Subject: [PATCH] Fix exceptions with using --yaml in containerapp create/update --- src/containerapp/azext_containerapp/_utils.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/containerapp/azext_containerapp/_utils.py b/src/containerapp/azext_containerapp/_utils.py index b1b3fa9bf9a..6dc7b1198a3 100644 --- a/src/containerapp/azext_containerapp/_utils.py +++ b/src/containerapp/azext_containerapp/_utils.py @@ -428,8 +428,14 @@ def _add_or_update_tags(containerapp_def, tags): def _object_to_dict(obj): - import json - return json.loads(json.dumps(obj, default=lambda o: o.__dict__)) + import json, datetime + + def default_handler(x): + if isinstance(x, datetime.datetime): + return x.isoformat() + return x.__dict__ + + return json.loads(json.dumps(obj, default=default_handler)) def _to_camel_case(snake_str): @@ -499,10 +505,10 @@ def _remove_dapr_readonly_attributes(daprcomponent_def): def update_nested_dictionary(orig_dict, new_dict): # Recursively update a nested dictionary. If the value is a list, replace the old list with new list - import collections + from collections.abc import Mapping for key, val in new_dict.items(): - if isinstance(val, collections.Mapping): + if isinstance(val, Mapping): tmp = update_nested_dictionary(orig_dict.get(key, {}), val) orig_dict[key] = tmp elif isinstance(val, list):