From 0093c9c236c2df455524fa56a98a1039531d8e8c Mon Sep 17 00:00:00 2001 From: Chris Lenk Date: Mon, 1 Aug 2022 09:18:42 -0400 Subject: [PATCH] Fix MongoBackend.clear_db() so it won't try to delete nonexistent databases --- medallion/backends/mongodb_backend.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/medallion/backends/mongodb_backend.py b/medallion/backends/mongodb_backend.py index e0e06ab..d7d85f0 100644 --- a/medallion/backends/mongodb_backend.py +++ b/medallion/backends/mongodb_backend.py @@ -554,12 +554,11 @@ def initialize_mongodb_with_data(self, filename): def clear_db(self): if "discovery_database" in self.client.list_database_names(): log.info("Clearing database") + discovery_db = self.client["discovery_database"] + api_root_info = discovery_db["api_root_info"] + for api_info in api_root_info.find({}): + self.client.drop_database(api_info["_name"]) self.client.drop_database("discovery_database") - discovery_db = self.client["discovery_database"] - api_root_info = discovery_db["api_root_info"] - for api_info in api_root_info.find({}): - self.client.drop_database(api_info["_name"]) - self.client.drop_database("discovery_database") # db with empty tables log.info("Creating empty database") discovery_db = self.client.get_database("discovery_database")