You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When model have integer field as primarykey, above issue raised
but,
when model have uuid field as primarykey , it raise
ValueError('badly formed hexadecimal UUID string')
here is the code
app.py
import uuid as uuid_pkg
from sqladmin import Admin, ModelView
from fastapi import FastAPI
from sqlmodel import Field, Session, SQLModel, create_engine, select
class Hero(SQLModel, table=True):
uuid: uuid_pkg.UUID = Field(
default_factory=uuid_pkg.uuid4,
primary_key=True,
index=True,
nullable=False,
)
name: str
secret_name: str
age: int | None = None
sqlite_file_name = "database.db"
sqlite_url = f"sqlite:///{sqlite_file_name}"
engine = create_engine(sqlite_url, echo=True)
def create_db_and_tables():
SQLModel.metadata.create_all(engine)
app = FastAPI()
@app.on_event("startup")
def on_startup():
create_db_and_tables()
@app.post("/heroes/")
def create_hero(hero: Hero):
with Session(engine) as session:
session.add(hero)
session.commit()
session.refresh(hero)
return hero
@app.get("/heroes/")
def read_heroes():
with Session(engine) as session:
heroes = session.exec(select(Hero)).all()
return heroes
admin = Admin(app, engine)
class HeroAdmin(ModelView, model=Hero): ...
admin.add_view(HeroAdmin)
when I visit for
http://127.0.0.1:8000/admin/hero/details/a090e833-1f29-46b3-bfc6-287e523bd3df
It works fine
but, when
http://127.0.0.1:8000/admin/hero/details/random
it raise ValueError('badly formed hexadecimal UUID string')
requirements.txt
sqlmodel
sqladmin
fastapi[all]
Steps to reproduce the bug
No response
Expected behavior
No response
Actual behavior
No response
Debugging material
No response
Environment
window 11 , python 3.11, latest sqlmodel
Additional context
No response
The text was updated successfully, but these errors were encountered:
Checklist
master
.Describe the bug
I got valueError when I pass unneccessary parameter
for example
https://sqladmin-demo.aminalaee.dev/admin/address/details/2nfd
When model have integer field as primarykey, above issue raised
but,
when model have uuid field as primarykey , it raise
ValueError('badly formed hexadecimal UUID string')
here is the code
Steps to reproduce the bug
No response
Expected behavior
No response
Actual behavior
No response
Debugging material
No response
Environment
window 11 , python 3.11, latest sqlmodel
Additional context
No response
The text was updated successfully, but these errors were encountered: