{"id":909,"hash":"4562790e6d05afd9cf52733c94bc2cdb6f5a30a905a4519a8e1fd68cd844901f","pattern":"FastAPI - GET request results in typeerror (value is not a valid dict)","full_message":"this is my database schema.\n\nI defined my Schema like this:\n\nfrom pydantic import BaseModel\n\nclass Userattribute(BaseModel):\n    name: str\n    value: str\n    user_id: str\n    id: str\n\nThis is my model:\n\nclass Userattribute(Base):\n    __tablename__ = \"user_attribute\"\n\n    name = Column(String)\n    value = Column(String)\n    user_id = Column(String)\n    id = Column(String, primary_key=True, index=True)\n\nIn a crud.py I define a get_attributes method.\n\ndef get_attributes(db: Session, skip: int = 0, limit: int = 100):\n    return db.query(models.Userattribute).offset(skip).limit(limit).all()\n\nThis is my GET endpoint:\n\n@app.get(\"/attributes/\", response_model=List[schemas.Userattribute])\ndef read_attributes(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):\n    users = crud.get_attributes(db, skip=skip, limit=limit)\n    print(users)\n    return users\n\nThe connection to the database seems to work, but a problem is the datatype:\n\npydantic.error_wrappers.ValidationError: 7 validation errors for Userattribute\nresponse -> 0\n  value is not a valid dict (type=type_error.dict)\nresponse -> 1\n  value is not a valid dict (type=type_error.dict)\nresponse -> 2\n  value is not a valid dict (type=type_error.dict)\nresponse -> 3\n  value is not a valid dict (type=type_error.dict)\nresponse -> 4\n  value is not a valid dict (type=type_error.dict)\nresponse -> 5\n  value is not a valid dict (type=type_error.dict)\nresponse -> 6\n  value is not a valid dict (type=type_error.dict)\n\nWhy does FASTApi expect a dictionary here? I don´t really understand it, since I am not able to even print the response. How can I fix this?","ecosystem":"pypi","package_name":"get","package_version":null,"solution":"Pydantic 2 changed how models gets configured, so if you're using the most recent version of Pydantic, see the section named Pydantic 2 below.\n\nSQLAlchemy does not return a dictionary, which is what pydantic expects by default. You can configure your model to also support loading from standard orm parameters (i.e. attributes on the object instead of dictionary lookups):\n\nclass Userattribute(BaseModel):\n    name: str\n    value: str\n    user_id: str\n    id: str\n\n    class Config:\n        orm_mode = True\n\nYou can also attach a debugger right before the call to return to see what's being returned.\n\nSince this answer has become slightly popular, I'd like to also mention that you can make orm_mode = True the default for your schema classes by having a common parent class that inherits from BaseModel:\n\nclass OurBaseModel(BaseModel):\n    class Config:\n        orm_mode = True\n\nclass Userattribute(OurBaseModel):\n    name: str\n    value: str\n    user_id: str\n    id: str\n\nThis is useful if you want to support orm_mode for most of your classes (and for those where you don't, inherit from the regular BaseModel).\n\nPydantic 2\n\nPydantic 2 has replaced the internal Config class with a model_config field:\n\nfrom pydantic import ConfigDict\n\nclass OurBaseModel(BaseModel):\n    model_config = ConfigDict(from_attributes=True)\n\nThis works in the same way as the old orm_mode.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/69504352/fastapi-get-request-results-in-typeerror-value-is-not-a-valid-dict","votes":35,"created_at":"2026-04-19T04:51:59.334075+00:00","updated_at":"2026-04-19T04:52:10.774314+00:00"}