Skip to content

Commit

Permalink
Better error on missing schema (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
palfrey authored Dec 21, 2022
1 parent 1185468 commit e47382d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dj_database_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test_dj_database_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit e47382d

Please sign in to comment.