Skip to content

fix: auth route conflict #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

VishnuSanal
Copy link
Contributor

Description

This PR fixes #982

Summary

This PR does fix authenticated routes with different method but same path causing conflict

PR Checklist

Please ensure that:

  • The PR contains a descriptive title
  • The PR contains a descriptive summary of the changes
  • You build and test your changes before submitting a PR.
  • You have added relevant documentation
  • You have added relevant tests. We prefer integration tests wherever possible

Pre-Commit Instructions:

Copy link

vercel bot commented Oct 18, 2024

@VishnuSanal is attempting to deploy a commit to the sparckles Team on Vercel.

A member of the Team first needs to authorize it.

@VishnuSanal
Copy link
Contributor Author

todo:

  • fix tests
  • please comment on the approach @sansyrox

@VishnuSanal VishnuSanal requested a review from sansyrox October 22, 2024 05:24
Copy link
Member

@sansyrox sansyrox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @VishnuSanal 👋

Overall , I like the approach ✨

I can do a review on the execution when it is up for review 😄

@VishnuSanal VishnuSanal marked this pull request as ready for review October 24, 2024 14:04
@VishnuSanal VishnuSanal requested a review from sansyrox October 24, 2024 14:04
Copy link

codspeed-hq bot commented Oct 24, 2024

CodSpeed Performance Report

Merging #987 will not alter performance

Comparing VishnuSanal:fix-auth-route-conflict (cac2435) with main (608fefd)

Summary

✅ 138 untouched benchmarks

@sansyrox
Copy link
Member

Hey @VishnuSanal , can you fetch the latest changes here??

Copy link

vercel bot commented Oct 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
robyn ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 7, 2025 7:29am

Co-authored-by: Sanskar Jethi <29942790+sansyrox@users.noreply.github.com>
@VishnuSanal VishnuSanal requested a review from sansyrox October 31, 2024 05:12
@alissonpelizaro
Copy link

Hi all, same issue here.

Any blockers for merging this? Let me know if I can help somehow!

@sansyrox
Copy link
Member

sansyrox commented Nov 7, 2024

Hey @alissonpelizaro 👋

Apologies for the delay in review. I planned to review this over the weekend. If possible, could you do an initial review please?

Comment on lines +342 to +347
HttpMethod.GET,
async_inner_handler,
injected_dependencies,
)
else:
self.add_route(middleware_type, endpoint, inner_handler, injected_dependencies)
self.add_route(middleware_type, endpoint, HttpMethod.GET, inner_handler, injected_dependencies)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a GET http method? Is a middleware always treated as a get request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a GET http method? Is a middleware always treated as a get request?

@sansyrox we are defaulting to GET. previously the value added to routes were just the endpoint, which caused the key conflicts. with this PR, we are making it "<http_method>/". and, I am defaulting all middleware requests to GET. do you think it is a bad idea? I have also tried making it "<middleware_type>/" (code here: https://github.com/VishnuSanal/Robyn/tree/fix-auth-route-conflict-new), but that breaks the middleware tests & I am unable to find a way around. what do you think? which approach to follow?

Copy link
Contributor Author

@VishnuSanal VishnuSanal May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a GET http method? Is a middleware always treated as a get request?

update:

yes, here, the req.method() returns GET for all middleware requests. I now realize that this is why the approach on my previous comment didn't work.

Copy link
Contributor

@k4976 k4976 May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a GET http method? Is a middleware always treated as a get request?

@sansyrox
This is just to fulfill the trait definition requirement as defined in mod.rs
if you pass anything here, it will still work
this is middleware router which works differently than base/global router which do lookup based on method + endpoint

Copy link
Member

@sansyrox sansyrox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR needs some more work and is up for grabs as @VishnuSanal is unfortunately away for some time.

Copy link
Contributor

@k4976 k4976 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VishnuSanal
All looks good to me, except the variable names

Do use correct name which represent their actual property
Like route_type used in python to pass http_method but same parameter name is used as middleware_type in rust which creates little bit confusion,
so please avoid that
so use http_method where it's route_type and use middleware_type where it's of type middleware_type

some variables are used wrongly before also, do check and fix them also
here are some files:
https://github.com/sparckles/Robyn/blob/main/src/routers/middleware_router.rs

@VishnuSanal
Copy link
Contributor Author

@k4976 thanks for your review. but I have some questions.

route_type used in python to pass http_method but same parameter name is used as middleware_type in rust

use http_method where it's route_type and use middleware_type where it's of type middleware_type

I didn't quite get this 🤔

we are using:

for middleware_type, endpoint, function, route_type in route_middlewares:
        server.add_middleware_route(middleware_type, endpoint, function, route_type)

and the signature for the same on server.rs is:

pub fn add_middleware_route(
        &self,
        middleware_type: &MiddlewareType,
        route: &str,
        function: FunctionInfo,
        http_method: HttpMethod,
    )

here, the middleware_type & http_method are of the same type, right? am I missing something? please CMIIW.

some variables are used wrongly before also, do check and fix them also here are some files: https://github.com/sparckles/Robyn/blob/main/src/routers/middleware_router.rs

I don't think this is the scope of this PR. please create an issue & let's address it in another PR :)

Copy link

recurseml bot commented May 27, 2025

⚠️ Only 5 files will be analyzed due to processing limits.

Copy link

recurseml bot commented May 27, 2025

😱 Found 2 issues. Time to roll up your sleeves! 😱

@VishnuSanal VishnuSanal marked this pull request as ready for review June 7, 2025 07:45
@VishnuSanal VishnuSanal requested a review from sansyrox June 7, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Authenticated routes with different method but same path causes conflict.
4 participants