From 401572996d336d3bc95a009fc45adafb697e226e Mon Sep 17 00:00:00 2001 From: Cassowary Rusnov Date: Mon, 6 Mar 2023 10:58:26 -0800 Subject: [PATCH] Add catching for the error that can happen if an object type does not exist --- confdump.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/confdump.py b/confdump.py index 7ac54ab..8d339dc 100644 --- a/confdump.py +++ b/confdump.py @@ -222,6 +222,16 @@ def parse_arguments() -> argparse.Namespace: return parser.parse_args() +def wrap_api_get(api, obj, args=None): + if args is None: + args = [] + try: + return api.get(obj, args) + except civicrmapi4.civicrmapi4.CallFailed: + logging.error("Could not fetch {}".format(obj)) + return [] + + def main() -> int: args = parse_arguments() @@ -261,14 +271,14 @@ def main() -> int: for table in DUMP_TRIVIAL: output = args.output / (table + ".json") - data = api.get(table) + data = wrap_api_get(api, table) if data: print("dumping", table) with output.open("w") as of: of.write(json.dumps(data)) # dump org contacts output = args.output / ("Contact.json") - data = api.get("Contact", where=[["contact_sub_type", "CONTAINS", "Political_Party"]]) + data = wrap_api_get(api, "Contact", where=[["contact_sub_type", "CONTAINS", "Political_Party"]]) if data: print("dumping parties") with output.open("w") as of: