sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.
https://sanic.dev
MIT License
18.09k stars 1.55k forks source link

Enforce unique route names #2641

Open ahopkins opened 1 year ago

ahopkins commented 1 year ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe.

No response

Describe the solution you'd like

In v23.3 we will begin enforcing unique route names. We will need to force routes with multiple hosts to have a unique name with something like this:

diff --git a/sanic/router.py b/sanic/router.py
index b68fde3b..b2e0fc69 100644
--- a/sanic/router.py
+++ b/sanic/router.py
@@ -139,6 +139,9 @@ class Router(BaseRouter):
             route.extra.static = static
             route.extra.error_format = error_format

+            if len(hosts) > 1 and host:
+                route.name = f"{route.name}__host_{host.replace('.', '_')}"
+
             if error_format:
                 check_error_format(route.extra.error_format)

Additional context

No response

ChihweiLHBird commented 1 year ago

Was this added in 23.3?