diff --git a/dbbackup/management/commands/dbbackup.py b/dbbackup/management/commands/dbbackup.py index 7172e12..75f0c44 100644 --- a/dbbackup/management/commands/dbbackup.py +++ b/dbbackup/management/commands/dbbackup.py @@ -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( @@ -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. diff --git a/dbbackup/tests/commands/test_dbbackup.py b/dbbackup/tests/commands/test_dbbackup.py index 11fbaed..4325a37 100644 --- a/dbbackup/tests/commands/test_dbbackup.py +++ b/dbbackup/tests/commands/test_dbbackup.py @@ -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) diff --git a/docs/changelog.rst b/docs/changelog.rst index 176b757..3ae3ce0 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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) ------------------