Coder Social home page Coder Social logo

Comments (11)

ahopkins avatar ahopkins commented on June 23, 2024 3

Released: https://pypi.org/project/sanic-routing/0.7.2/

from sanic-routing.

ahopkins avatar ahopkins commented on June 23, 2024 2

I see the problem. You are indeed correct this is a 🐛

I do not think it will be a difficult fix, but I am also not entirely sure of a good workaround yet. I will try to get an 0.7.2 out this weekend.

Thank you for providing the simple, easy to reproduce test case. This makes it very simple for me to narrow down the issue, and provides us with a pattern for regression testing.

from sanic-routing.

ahopkins avatar ahopkins commented on June 23, 2024 2

Here's the diff of the fix. If you have a chance to make the PR. If not, I can get to it later tonight.

diff --git a/sanic_routing/router.py b/sanic_routing/router.py
index 8e964d6..210927d 100644
--- a/sanic_routing/router.py
+++ b/sanic_routing/router.py
@@ -424,9 +424,10 @@ class BaseRouter(ABC):
             )
             route_idx: t.Union[str, int] = 0
 
+            holder = []
             if len(group.routes) > 1:
                 route_idx = "route_idx"
-                Node._inject_method_check(src, 1, group)
+                Node._inject_method_check(holder, 2, group)
 
             src.extend(
                 [
@@ -438,6 +439,7 @@ class BaseRouter(ABC):
                         1,
                     ),
                     Line("if match:", 1),
+                    *holder,
                     Line("basket['__params__'] = match.groupdict()", 2),
                     Line(
                         (

from sanic-routing.

wochinge avatar wochinge commented on June 23, 2024 1

Thanks for jumping so quickly on this! This is really great community support! 🙌🏻

Thank you for providing the simple, easy to reproduce test case.

haha 😆 I'm often on the other side at Rasa so I know the pain of a maintainer 😄

from sanic-routing.

ahopkins avatar ahopkins commented on June 23, 2024 1

haha laughing I'm often on the other side at Rasa so I know the pain of a maintainer smile

Nice to finally "meet" you

from sanic-routing.

wochinge avatar wochinge commented on June 23, 2024 1

Thank you so much! This was really outstanding community support! 🙌🏻 Keep up the great work! 🚀

from sanic-routing.

wochinge avatar wochinge commented on June 23, 2024

It seems this was introduced in 0.7.1. Can't reproduce with 0.7.0

from sanic-routing.

ahopkins avatar ahopkins commented on June 23, 2024

As way of explanation of what is happening... this is a portion of the generated router with my own annotations:

    # This section only appears RIGHT BEFORE a grouped set of routes. 
    # In this case, since the same route has a POST and PUT, it helps direct to the correct one
    if method in frozenset({'PUT'}):
        route_idx = 0
    elif method in frozenset({'POST'}):
        route_idx = 1
    else:
        raise NoMethod

    # Matching for "/conversation/<conversation_id:path>/tracker/events"
    match = router.matchers[0].match(path)
    if match:
        basket['__params__'] = match.groupdict()
        return router.regex_routes[('conversation', '<__dynamic__:path>', 'tracker', 'events')][route_idx], basket

    # Matching for "/conversation/<conversation_id:path>/story"
    match = router.matchers[1].match(path)
    if match:
        basket['__params__'] = match.groupdict()
        return router.regex_routes[('conversation', '<__dynamic__:path>', 'story')][0], basket
    raise NotFound

So, the solution is probably to move the method checking inside the match conditional.

from sanic-routing.

wochinge avatar wochinge commented on June 23, 2024

You're my hero! I'll try it out!

from sanic-routing.

wochinge avatar wochinge commented on June 23, 2024

Sweet - it works. I'll create a PR - just need to write a test

from sanic-routing.

ahopkins avatar ahopkins commented on June 23, 2024

It helps that it was a simple fix 😆

from sanic-routing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.