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 @@ class DatabaseTestSuite(unittest.TestCase): 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()