import decimal
import msgspec
import litestar
class Foo1(msgspec.Struct):
bar: decimal.Decimal
class Foo2(msgspec.Struct):
bar: float
@litestar.get("/1")
async def test1() -> Foo1:
d = decimal.Decimal(123.00)
return Foo1(bar=d)
@litestar.get("/2")
async def test2() -> Foo2:
d = decimal.Decimal(123.00)
return Foo2(bar=d)
app = litestar.Litestar(route_handlers=[test1, test2])
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, port=7777)
My response becomes a string.. shouldn't it be a float?
{"bar": "123"}
The reason I ask, is when I use asyncpg plugin, my numeric types are decimal. So in my msgspec, I'll type it as float so that it converts properly.
Why is this happening?