Skip to content

Commit

Permalink
Fix: DROP REPOSITORY now returns RepositoryMissingException
Browse files Browse the repository at this point in the history
With previous versions of CrateDB, it was `RepositoryUnknownException`.
  • Loading branch information
amotl committed Oct 4, 2023
1 parent 1ab9e11 commit bc80031
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/crate/crate-airflow-tutorial>.
Expand Down
8 changes: 8 additions & 0 deletions cratedb_retention/util/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 3 additions & 1 deletion cratedb_retention/util/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit bc80031

Please sign in to comment.