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

AttributeError: 'APIWebSocketRoute' object has no attribute 'methods' #38

Open
cheesycod opened this issue Apr 12, 2021 · 1 comment
Open

Comments

@cheesycod
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Yes, I want to use this with a api with Websockets as well
Describe the solution you'd like
A clear and concise description of what you want to happen.
Websocket support in fastapi versioner
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
I right now have my own middleware to handle these things but this looks better
Additional context
Add any other context or screenshots about the feature request here.

@smihaila
Copy link

smihaila commented Jun 16, 2021

Hi,

I'm looking for the same feature, namely the ability to decorate a @fastapi.APIRouter.websocket("/path") route with @fastapi_versioning.version(major, minor).

Currently getting the same error as cheesycod.

Actually, even without decorating a WebSocket-based FastAPI endpoint with @Version(major, minor), and having such decorators strictly at REST / non-WebSocket routes level, I'm still getting the same error (AttributeError: 'APIWebSocketRoute' object has no attribute 'methods') in the line that creates a VersionedFastAPI instance.

... and to mitigate the error, I have to re-structure the routers registration (i.e. FastAPI.include_router() calls) so that any WebSocket-based router comes AFTER creating the VersionedFastAPI instance. Like this:

app: FastAPI = FastAPI(title=APP_NAME, ...)
app.include_router(some_non_websocket_router)

app: VersionedFastAPI = VersionedFastAPI(app, ...)
app.add_middleware(...)

app.include_router(some_websocket_router)

Thank you.

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

No branches or pull requests

2 participants