Skip to content

Commit

Permalink
improve exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
viseshrp committed Dec 8, 2024
1 parent 2c24469 commit bbd8d60
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ansys/dynamicreporting/core/serverless/adr.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ def backup_database(
if database != "default" and database not in self._databases:
raise ADRException(f"{database} must be configured first using the 'databases' option.")
target_dir = Path(output_directory).resolve(strict=True)
if not target_dir.is_dir():
raise InvalidPath(extra_detail=f"{output_directory} is not a valid directory.")
# call django management command to dump the database
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
file_path = target_dir / f"backup_{timestamp}.json{'.gz' if compress else ''}"
Expand All @@ -308,14 +310,14 @@ def backup_database(
def restore_database(self, input_file: str, *, database: str = "default") -> None:
if database != "default" and database not in self._databases:
raise ADRException(f"{database} must be configured first using the 'databases' option.")
input_file = Path(input_file).resolve(strict=True)
if not input_file.is_file():
raise InvalidPath(extra_detail=str(input_file))
backup_file = Path(input_file).resolve(strict=True)
if not backup_file.is_file():
raise InvalidPath(extra_detail=f"{input_file} is not a valid file.")
# call django management command to load the database
try:
management.call_command(
"loaddata",
str(input_file),
str(backup_file),
"--database",
database,
"--ignorenonexistent",
Expand Down

0 comments on commit bbd8d60

Please sign in to comment.