Skip to content

Commit

Permalink
By default assume HOST is localhost for postgres databases. (#521)
Browse files Browse the repository at this point in the history
* fix #520

* tests for #520

* update changelog to reflect #520

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* rename dump without host test

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
bckohan and pre-commit-ci[bot] authored Jul 19, 2024
1 parent 6187954 commit 16ca67c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
6 changes: 1 addition & 5 deletions dbbackup/db/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
from urllib.parse import quote

from .base import BaseCommandDBConnector
from .exceptions import DumpError

logger = logging.getLogger("dbbackup.command")


def create_postgres_uri(self):
host = self.settings.get("HOST")
if not host:
raise DumpError("A host name is required")

host = self.settings.get("HOST") or "localhost"
dbname = self.settings.get("NAME") or ""
user = quote(self.settings.get("USER") or "")
password = self.settings.get("PASSWORD") or ""
Expand Down
3 changes: 3 additions & 0 deletions dbbackup/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@
}
},
}

# let there be silence
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
7 changes: 3 additions & 4 deletions dbbackup/tests/test_connectors/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from django.test import TestCase

from dbbackup.db.exceptions import DumpError
from dbbackup.db.postgresql import (
PgDumpBinaryConnector,
PgDumpConnector,
Expand Down Expand Up @@ -41,10 +40,10 @@ def test_create_dump(self, mock_dump_cmd):
# Test cmd
self.assertTrue(mock_dump_cmd.called)

def test_create_dump_without_host_raises_error(self, mock_dump_cmd):
def test_create_dump_without_host(self, mock_dump_cmd):
# this is allowed now: https://github.com/jazzband/django-dbbackup/issues/520
self.connector.settings.pop("HOST", None)
with self.assertRaises(DumpError):
self.connector.create_dump()
self.connector.create_dump()

def test_password_but_no_user(self, mock_dump_cmd):
self.connector.settings.pop("USER", None)
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
Unreleased
----------

* Default HOST to localhost for postgres databases. https://github.com/jazzband/django-dbbackup/issues/520
* Add PostgreSQL Schema support by @angryfoxx in https://github.com/jazzband/django-dbbackup/pull/507
* 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
Expand Down

0 comments on commit 16ca67c

Please sign in to comment.