Skip to content
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

ValueError on passing unexcepted parameter #766

Open
2 tasks done
BhuwanPandey opened this issue May 13, 2024 · 0 comments
Open
2 tasks done

ValueError on passing unexcepted parameter #766

BhuwanPandey opened this issue May 13, 2024 · 0 comments

Comments

@BhuwanPandey
Copy link
Contributor

BhuwanPandey commented May 13, 2024

Checklist

  • The bug is reproducible against the latest release or master.
  • There are no similar issues or pull requests to fix it yet.

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant