Skip to content

Could not refresh instance #536

Open
@AshikurRahman-sec

Description

@AshikurRahman-sec

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

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>'

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions