First Check
Commit to Help
Example Code
from typing import Optional
from sqlmodel import Field, SQLModel
class Server(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
ip: str
health_status: Optional[str] = None
cpu_cores: Optional[int] = None
@router.post("/add")
def add_server(item:Server):
return server_action.add_server(item)
def add_server(item):
with Session(engine) as session:
session.add(item)
session.commit()
session.refresh(item) # could not refresh instance
return item
Description
In sql model documentation I saw an example of session.refresh() but when I am trying to implement this in my fastapi project this not working and raise exception that is could not refresh instance and also I am trying to print item.id, this is not also working, raise exception that is expired.
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.10.6
Additional Context
raise sa_exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: Could not refresh instance '<Server at 0x7f69b549f500>'
First Check
Commit to Help
Example Code
Description
In sql model documentation I saw an example of session.refresh() but when I am trying to implement this in my fastapi project this not working and raise exception that is could not refresh instance and also I am trying to print item.id, this is not also working, raise exception that is expired.
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.10.6
Additional Context
raise sa_exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: Could not refresh instance '<Server at 0x7f69b549f500>'