-
-
Notifications
You must be signed in to change notification settings - Fork 258
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
BaseRouter and Router have different signatures for add_route #1035
Comments
Hey @dave42w 👋 I just want to show that every router needs to have an |
I'm not sure :-) I'll have a think |
I think we could fix by creating two more ABCs. One for the parameters eg BaseRouteArg and one for the return type eg BaseRouteReturn For each type of Router we need two classes eg
That seems a bit clumsy, but if we create these as dataclasses, we can move argument validation into them. That would simplify the add_route methods, which are currently long with deep nesting. So now we have
|
If the constructor for RouterRouteArg has exactly the same arguments as the Router.add_route currently does then code changes should be minimal. eg In Robyn.add_route we construct a RouterRouteArg before passing it to |
Hi @sansyrox This passes mypy. It's slightly odd to me that the ABC class needs to be used for the argument but the specific subclass can be used for the return. That's why I've added the assert.
Are you interested in a PR for this? |
Hi @sansyrox, I've been looking at this add_route issue a bit more. I'm finding it confusing, trying to follow the logic. Are there two separate stores of routes (Robyn object as they are declared, in Rust as the app is started)? In the Robyn instance within the router objects:
which (I think) are only populated by these methods
then there are routing tables in rust which are created for each server instance from the python Robyn object? This differs from the architecture drawing which implies that Rust and Python are using the same router. If I'm right then my understanding is
I would like to understand this as it feels that router.py could be refactored to be simpler without changing either the app developer experience (which I like) or the performance (which I like). That would help us get things like nesting subrouters and hopefully it would also simplify authentication and authorisation. What I am thinking is that we simplify so the Robyn class has one Router instance. That Router instance holds it's own routes and potentially multiple subrouters. The subrouters also hold only their own routes and potentially multiple subrouters. This simplifies the code (we don't need both Router and SubRouter) we simply create as many Routers as we want. Any of them can become a subrouter by adding them to another Router. We make one Router the "master" by adding it to the Robyn instance. It will be slower to parse into a complete list of routes (probably using recursion) but that is only done once to create the full route table in rust. I guess we could add a means to get all the worker processes to reload their route table if we want to be able to dynamically change it (for example we could implement a dynamic multi-tenancy application. When we add a new tenant we add a whole new set of routes for them by adding an extra subrouter to the main application Router and then reload all the routes). Depending on how we want to do things we could allow different middleware for each router, so supporting different authentication/authorisations policies by router. I'm not yet sure how openapi and web_sockets fit into this Does this make any sense or have I misread the code? |
Hey @dave42w 👋 I think I partly understand your concern. But
What do you mean by this or example we could implement a dynamic multi-tenancy application. When we add a new tenant we add a whole new set of routes for them by adding an extra subrouter to the main application Router and then reload all the routes). ? |
And there is only one Router instance, which holds all the routes. Why would you want to change that? |
Hi @sansyrox
Well before suggesting changes it is critical that I understand the existing code and design :-) I understand that in the applications Robyn instance there are three Router instances
What I'm unclear about is when the server is started and the worker threads start do these use the routes directly from the same 3 instance variables in the apps Robyn instance? As I looked at the rust code it seemed to me that this makes a copy of the routes eg in server.rs
and
So it seems to me that we have two different add_route mechanisms.
Am I correct? |
Bug Description
According to mypy None of the subclasses of BaseRouter correctly implement the abstractmethod add_route.
vs
vs
vs
The mypy errors are:
I can't find any use of BaseRouter in the codebase.
Options:
Steps to Reproduce
Your operating system
Linux
Your Python version (
python --version
)3.12
Your Robyn version
main branch
Additional Info
No response
The text was updated successfully, but these errors were encountered: