Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serialize_response #18

Open
DevBadi opened this issue Jan 31, 2023 · 0 comments
Open

serialize_response #18

DevBadi opened this issue Jan 31, 2023 · 0 comments

Comments

@DevBadi
Copy link

DevBadi commented Jan 31, 2023

I was trying to do the same what you did with the response_model and i created

Schema

class UserCreate(BaseModel):
    email: EmailStr
    password: str


class UserOut(BaseModel):
    id: str
    email: EmailStr
    created_at: datetime

    class Config:
        orm_mode = True

Model

class User(Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True, nullable=False)
    email = Column(String, nullable=False, unique=True)
    password = Column(String, nullable=False)
    created_at = Column(TIMESTAMP(timezone=True),
                        nullable=False, server_default=text('now()'))

Router

@router.get("/{id}", response_model=schemas.UserOut)
def get_user(id: int, db: Session = Depends(get_db)):
    user = db.query(models.User).filter(models.User.id == id).first()
    if not user:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=" this id is not found")
    return {"message": user}

Libs

anyio==3.6.2
bcrypt==4.0.1
click==8.1.3
dnspython==2.3.0
email-validator==1.3.1
fastapi==0.89.1
greenlet==2.0.1
h11==0.14.0
httptools==0.5.0
idna==3.4
passlib==1.7.4
psycopg2==2.9.5
pydantic==1.10.4
python-dotenv==0.21.1
PyYAML==6.0
sniffio==1.3.0
SQLAlchemy==1.4.23
starlette==0.22.0
typing_extensions==4.4.0
uvicorn==0.20.0
uvloop==0.17.0
watchfiles==0.18.1
websockets==10.4

Error :

in serialize_response
    raise ValidationError(errors, field.type_)
pydantic.error_wrappers.ValidationError: 3 validation errors for UserOut
response -> id
  field required (type=value_error.missing)
response -> email
  field required (type=value_error.missing)
response -> created_at
  field required (type=value_error.missing)

Question :

am I missing something here, i did the samething but i still get this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant