From 5b2253e3caf59ab30b7bea4301c1dcd9d5559c97 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Wed, 4 Oct 2023 00:29:29 +0200 Subject: [PATCH] Fix: `DROP REPOSITORY` now returns `RepositoryMissingException` With previous versions of CrateDB, it was `RepositoryUnknownException`. --- CHANGES.md | 4 ++++ cratedb_retention/util/data.py | 8 ++++++++ cratedb_retention/util/database.py | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2e7623b8..0821038f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,10 @@ - Use full-qualified table names everywhere. +- Fix: Compensate for `DROP REPOSITORY` now returning `RepositoryMissingException` + when the repository does not exist. With previous versions of CrateDB, it was + `RepositoryUnknownException`. + ## 2023/06/27 0.0.0 - Import "data retention" implementation from . diff --git a/cratedb_retention/util/data.py b/cratedb_retention/util/data.py index e038fc79..5778f9c7 100644 --- a/cratedb_retention/util/data.py +++ b/cratedb_retention/util/data.py @@ -7,3 +7,11 @@ def jd(data: t.Any): Pretty-print JSON with indentation. """ print(json.dumps(data, indent=2)) # noqa: T201 + + +def str_contains(haystack, *needles): + """ + Whether haystack contains any of the provided needles. + """ + haystack = str(haystack) + return any(needle in haystack for needle in needles) diff --git a/cratedb_retention/util/database.py b/cratedb_retention/util/database.py index bb871a7a..be1b63c6 100644 --- a/cratedb_retention/util/database.py +++ b/cratedb_retention/util/database.py @@ -4,6 +4,8 @@ from sqlalchemy.exc import ProgrammingError from sqlalchemy.sql.elements import AsBoolean +from cratedb_retention.util.data import str_contains + def run_sql(dburi: str, sql: str, records: bool = False): return DatabaseAdapter(dburi=dburi).run_sql(sql=sql, records=records) @@ -70,7 +72,7 @@ def drop_repository(self, name: str): sql = f"DROP REPOSITORY {name};" self.run_sql(sql) except ProgrammingError as ex: - if "RepositoryUnknownException" not in str(ex): + if not str_contains(ex, "RepositoryUnknownException", "RepositoryMissingException"): raise def ensure_repository_fs(