Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,10 +924,11 @@ def handler(request):
self.blueprint(item, **params)
return
if blueprint.name in self.blueprints:
assert self.blueprints[blueprint.name] is blueprint, (
'A blueprint with the name "%s" is already registered. '
"Blueprint names must be unique." % (blueprint.name,)
)
if self.blueprints[blueprint.name] is not blueprint:
raise ValueError(
f"A blueprint with the name '{blueprint.name}' is "
"already registered. Blueprint names must be unique."
)
else:
Comment thread
ChihweiLHBird marked this conversation as resolved.
self.blueprints[blueprint.name] = blueprint
self._blueprint_order.append(blueprint)
Expand Down
3 changes: 2 additions & 1 deletion sanic/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ def parse_xforwarded(headers, config) -> Options | None:
proxies_count = config.PROXIES_COUNT
addr = real_ip_header and headers.getone(real_ip_header, None)
if not addr and proxies_count:
assert proxies_count > 0
if proxies_count <= 0:
raise ValueError("PROXIES_COUNT must be a positive integer")
Comment thread
ChihweiLHBird marked this conversation as resolved.
try:
# Combine, split and filter multiple headers' entries
forwarded_for = headers.getall(config.FORWARDED_FOR_HEADER)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,12 +884,12 @@ def test_duplicate_blueprint(app: Sanic):

app.blueprint(bp)

with pytest.raises(AssertionError) as excinfo:
with pytest.raises(ValueError) as excinfo:
app.blueprint(bp1)

assert str(excinfo.value) == (
f'A blueprint with the name "{bp_name}" is already registered. '
"Blueprint names must be unique."
f"A blueprint with the name '{bp_name}' is "
"already registered. Blueprint names must be unique."
)


Expand Down
Loading