Home > OS >  I'm dealing with error "TypeError: Object of type Row is not JSON serializable" FastA
I'm dealing with error "TypeError: Object of type Row is not JSON serializable" FastA

Time:05-25

I have "many to many" relationship table. After fetching I'm trying sending result to a client but keep getting "TypeError: Object of type Row is not JSON serializable".

I'm able to print my response to see how data is in a list. But when I put it in return I get "TypeError: Object of type Row is not JSON serializable" error.

Here is my code:

@router.get("/{release_name}", response_model=int)
async def build_names_by_release(release_name: str, db: Session = Depends(get_database_session)):
   result = db.query(ReleaseNames, BuildNames).limit(50).all()

   // need here code to serialize it

   return JSONResponse(content=result)

What I think is we need to do ->

[({Row object}, {Row object}),({Row object}, {Row object})...({Row object}, {Row object})] -> 
[({JSON serialize object}, {JSON serialize object}), ({JSON serialize object}, {JSON serialize object})...({JSON serialize object}, {JSON serialize object})]

CodePudding user response:

this problem is about your response_model=int you can remove it or pass schema model to response model

  • Related