Skip to content
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

Remove usage of ctx in routing #2303

Closed
ahopkins opened this issue Nov 7, 2021 · 3 comments · Fixed by #2555
Closed

Remove usage of ctx in routing #2303

ahopkins opened this issue Nov 7, 2021 · 3 comments · Fixed by #2555

Comments

@ahopkins
Copy link
Member

ahopkins commented Nov 7, 2021

TLDR

Remove all Sanic reliance upon ctx values in the routing module.

Rationale

There are several locations throughout Sanic where the developer is provided with a ctx object to inject arbitrary values. The two most visible locations are Sanic.ctx and Request.ctx. However, this also exists for the router, routes, blueprints, and connections.

Only in routing does Sanic actually use the object for storing internal state. It will be much more consistent if Sanic never touches these objects, and therefore they can serve their original purpose: injection of arbitrary values without the worry of conflict.


Implementation

The reason that Sanic has used these values is so that sanic-routing can exist independently of sanic. So, from the perspective of sanic-routing, these objects are fulfilling their purpose and not being overburdened with values. Ultimately, however, this is somewhat moot as far as the developer is concerned as they need to be careful not to overwrite these values.

Therefore, the simplest approach is probably to add a state object into sanic-routing that looks and functions the same was as ctx, but is specifically intended for arbitrary "stateful" information coming from Sanic.

See #2300 and #2302

@ahopkins ahopkins added this to the v22.3 milestone Nov 7, 2021
@stale
Copy link

stale bot commented Mar 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions.

@stale stale bot added the stale label Mar 2, 2022
@ahopkins
Copy link
Member Author

ahopkins commented Mar 2, 2022

...

@stale stale bot removed the stale label Mar 2, 2022
@ahopkins ahopkins modified the milestones: v22.3, v22.9 Jun 26, 2022
@ahopkins
Copy link
Member Author

route.extra was added sanic-org/sanic-routing#65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant