From e47382d4abb8ced3f4c7956b60c55d82b7c87d52 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Wed, 21 Dec 2022 08:19:39 +0000 Subject: [PATCH 1/2] Better error on missing schema (#196) --- dj_database_url.py | 8 +++++++- test_dj_database_url.py | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dj_database_url.py b/dj_database_url.py index 39f7405..ac194a4 100644 --- a/dj_database_url.py +++ b/dj_database_url.py @@ -115,7 +115,13 @@ def parse( hostname = urlparse.unquote(hostname) # Lookup specified engine. - engine = SCHEMES[url.scheme] if engine is None else engine + if engine is None: + engine = SCHEMES.get(url.scheme) + if engine is None: + raise ValueError( + "No support for '%s'. We support: %s" + % (url.scheme, ", ".join(sorted(SCHEMES.keys()))) + ) port = ( str(url.port) diff --git a/test_dj_database_url.py b/test_dj_database_url.py index a10625a..0ed8b02 100644 --- a/test_dj_database_url.py +++ b/test_dj_database_url.py @@ -541,6 +541,10 @@ def test_persistent_connection_variables_config(self): assert url["CONN_MAX_AGE"] == 600 assert url["CONN_HEALTH_CHECKS"] is True + def test_bad_url_parsing(self): + with self.assertRaisesRegex(ValueError, "No support for 'foo'. We support: "): + dj_database_url.parse("foo://bar") + if __name__ == "__main__": unittest.main() From 7755b606ae1a183fd965981a69d318bb44a4e3f0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 21 Dec 2022 11:43:14 +0000 Subject: [PATCH 2/2] [pre-commit.ci] pre-commit autoupdate (#200) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pycqa/isort: 5.10.1 → v5.11.3](https://github.com/pycqa/isort/compare/5.10.1...v5.11.3) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7301e52..0041b4e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/pycqa/isort - rev: "5.10.1" + rev: "v5.11.3" hooks: - id: isort args: ["--profile", "black"]