Skip to content

Commit

Permalink
Respect DBBACKUP_DATABASES in dbbackup management command (#492)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Bakhit <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Archmonger <[email protected]>
  • Loading branch information
4 people authored Jan 30, 2024
1 parent 1b2ead2 commit 35b831f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dbbackup/management/commands/dbbackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ def handle(self, **options):
self.storage = get_storage()

self.database = options.get("database") or ""
database_keys = self.database.split(",") or settings.DATABASES

for database_key in database_keys:
for database_key in self._get_database_keys():
self.connector = get_connector(database_key)
if self.connector and self.exclude_tables:
self.connector.exclude.extend(
Expand All @@ -96,6 +95,9 @@ def handle(self, **options):
except StorageError as err:
raise CommandError(err) from err

def _get_database_keys(self):
return self.database.split(",") if self.database else settings.DATABASES

def _save_new_backup(self, database):
"""
Save a new backup file.
Expand Down
10 changes: 10 additions & 0 deletions dbbackup/tests/commands/test_dbbackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def test_path(self):
# tearDown
os.remove(self.command.path)

@patch("dbbackup.settings.DATABASES", ["db-from-settings"])
def test_get_database_keys(self):
with self.subTest("use --database from CLI"):
self.command.database = "db-from-cli"
self.assertEqual(self.command._get_database_keys(), ["db-from-cli"])

with self.subTest("fallback to DBBACKUP_DATABASES"):
self.command.database = ""
self.assertEqual(self.command._get_database_keys(), ["db-from-settings"])


@patch("dbbackup.settings.GPG_RECIPIENT", "test@test")
@patch("sys.stdout", DEV_NULL)
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Unreleased
----------

* Fix restore of database from S3 storage by reintroducing inputfile.seek(0) to utils.uncompress_file
* Fix bug where dbbackup management command would not respect settings.py:DBBACKUP_DATABASES

4.1.0 (2024-01-14)
------------------
Expand Down

0 comments on commit 35b831f

Please sign in to comment.