Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

pydantic.error_wrappers.ValidationError: 1 validation error response #478

Closed
Biscai opened this issue Aug 28, 2019 · 6 comments
Closed

pydantic.error_wrappers.ValidationError: 1 validation error response #478

Biscai opened this issue Aug 28, 2019 · 6 comments
Labels
question Question or problem question-migrate

Comments

@Biscai
Copy link

Biscai commented Aug 28, 2019

I have:

model.py

class ItemObjects(Base):
    __tablename__ = "OBJT"
    ID = Column(Integer, primary_key=True, index=True)
    O_MAILITEM = Column(String, index=True)

shema.py

class ItemObjects(ObjectsBase):
    ID:int
    O_MAILITEM:str

crud.py

def get_objects(db: Session, skip: int = 0, limit: int = 100):
    return db.query(models.ItemObjects).offset(skip).limit(limit).all()

I am using SQL Server in database.py. Connection with database is ok.

So in main.py:

@app.get("/objects/", response_model = schemas.ObjectsBase)
async def read_objects(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    lobjects = crud.get_objects(db, skip=skip, limit=limit)
    return lobjects

when i run i have received this error:
image
.

In database;
I have a table "OBJT" in database with same colunns [e.g. ID, O_MAILITEM, O_A_NAME, and others colunns].

Can you help me to solve this?

@Biscai Biscai added the question Question or problem label Aug 28, 2019
@dmontagu
Copy link
Collaborator

dmontagu commented Aug 28, 2019

I think the issue is that you need ObjectsBase to have orm_mode = True in its Config -- search for orm_mode here for more detail. Try that and report back?

@Biscai
Copy link
Author

Biscai commented Aug 29, 2019

I think the issue is that you need ObjectsBase to have orm_mode = True in its Config -- search for orm_mode here for more detail. Try that and report back?

Hi,
Thanks for your feedback, but return same error.
I put in Shema.py: class Config: orm_mode = True

@binbinah
Copy link

met the same question , any solution here?

@binbinah
Copy link

met the same question , any solution here?

find the answer:

previous:

@router.get('/info/get', response_model=schemas.QQMessage)
def read_qq_messages(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    message = crud.get_qq_messages(db, skip, limit)
    return message

after:

from typing import List

...

@router.get('/info/get', response_model=List[schemas.QQMessage])
def read_qq_messages(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    message = crud.get_qq_messages(db, skip, limit)
    return message

GET request's response_model is different from POST method

@tiangolo
Copy link
Owner

Thanks for the help @dmontagu!

Thanks for the report @binbinah!

@Biscai were you able to solve your problem? May we close this issue?

@Biscai
Copy link
Author

Biscai commented Nov 12, 2019

thanks for your help @binbinah !

@tiangolo the problem is solved. Thanks

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Question or problem question-migrate
Projects
None yet
Development

No branches or pull requests

4 participants