Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
Fix models to support pydantic orm_mode
Browse files Browse the repository at this point in the history
See GitHub PR fastapi#43
fastapi#43
See GitHub issue fastapi#72
fastapi#72

When viewing the user profile, name and email weren't showing up.

Docker Compose logs showed a pydantic error:
https://pydantic-docs.helpmanual.io/

```
backend_1        | pydantic.error_wrappers.ValidationError: 1 validation
                   error for User
backend_1        | response -> 0
backend_1        |   value is not a valid dict (type=type_error.dict)
```

Pydantic orm_mode is needed. This commit will update the database models
to use pydantic orm_mode, with cleaner syntax than the fix suggested in
issue fastapi#72 (by adding class Config directly to the base class).
  • Loading branch information
br3ndonland committed Dec 6, 2019
1 parent 44d8a43 commit efb0851
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions {{cookiecutter.project_slug}}/backend/app/app/models/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class ItemBase(BaseModel):
title: str = None
description: str = None

class Config:
orm_mode = True


# Properties to receive on item creation
class ItemCreate(ItemBase):
Expand Down
3 changes: 3 additions & 0 deletions {{cookiecutter.project_slug}}/backend/app/app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class UserBase(BaseModel):
is_superuser: Optional[bool] = False
full_name: Optional[str] = None

class Config:
orm_mode = True


class UserBaseInDB(UserBase):
id: int = None
Expand Down

0 comments on commit efb0851

Please sign in to comment.