Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: DROP REPOSITORY now returns RepositoryMissingException #50

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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