Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix models to support pydantic orm_mode
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
commit efb08515045519a9a8fb2aff545c6451e1aa2eb9
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