-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
hx and page decorators eat the JSON body of POST requests #68
Comments
Hi, The issue is probably in your template or a Jinja context processor for example. It's hard to say without seeing the full code. The decorators definitely do not consume the payload, they just forwards the resolved dependencies (including the payload) to actual route implementation, then execute the rendering using the request, the route's result, and its resolved dependencies (depending on how the Jinja context is created). You can test it like this: Create a Hello {{ value }}! Create a simple app next to the import os
from fastapi import FastAPI
from fastapi.templating import Jinja2Templates
from pydantic import BaseModel
from fasthx import Jinja
class Data(BaseModel):
value: str
basedir = os.path.abspath(os.path.dirname(__file__))
app = FastAPI()
templates = Jinja2Templates(directory=os.path.join(basedir, "templates"))
jinja = Jinja(templates)
@app.post("/hello")
@jinja.hx("hello.jinja")
async def hello(data: Data) -> Data:
return data Start the app with Without the (Edit: I used the latest version of FastAPI, currently 0.115.11) |
Thank you very much for your answer, very much appreciated. Your example works, I don't know why my work won't. I just upgraded FastAPI to 0.115.11 without luck. The Starlette error does not trigger without the decorator or if the decorator is before app.post(). But of course with the decorator before it won't work (as expected). And I checked that the error happened before any code in my function is executed. I do not use any fasthx custom rendering or anything, and I was indeed puzzled by the fact that the Request was just passed without any consumption. Get requests with URL variables work. Trying to breakpoint the hx decorator itself has the error thrown before any is executed. |
I could help you better with access to your actual code (contact info is in the readme). |
Sadly I can't really share any code, I am going to investigate further on my side. There are also VERY weird issues when using the decorators with Pydantic and Thanks a lot, I will come back if I find anything |
Do you mind if I close the issue? Feel free to re-open it if the bug is |
@signed-log Just out of curiosity: have you managed to find the issue? |
No, I was on a time crunch so I ended up just sending TemplateResponse manually |
When using the decorator it fails with a 422 error stating that input_model is None (sorry, I can't really provide a HTML boilerplate right now, it is a simple form) :
The request is correct as it is processed correctly without the decorator
System info
The text was updated successfully, but these errors were encountered: