master
.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
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]
No response
No response
No response
No response
window 11 , python 3.11, latest sqlmodel
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too