Clarification: FastCRUD methods assume primary key as “id” — not working for models with custom primary key fields #268
Unanswered
ujjawal-ibm
asked this question in
Q&A
Replies: 1 comment
-
|
@ujjawal-ibm try running ClusterCRUD.get(db, fsid="abcd-1234")FastCRUD uses kwargs to define filters, so you shouldn't have any problem just passing what your field is actually named. Essentially you may just pass as keyword arguments no matter what the filters are named |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Hi team 👋,
I wanted to clarify and possibly request enhancement support for FastCRUD when using models that have a primary key field name other than
id.Currently, the default methods like
fast_crud.get(db, id=value)orfast_crud.update(db, id=value, obj=value)internally assume that the primary key column is namedid.If our SQLModel has a custom primary key (for example,
fsid), these methods fail to locate the row.Example
It gives the error:
KeyError: 'id'Expected Behavior
Ideally, FastCRUD should detect and use the correct primary key field (in this case, fsid) automatically, similar to how SQLModel identifies it internally.
Question
Workaround Tried
For now, I’m using explicit SQLModel queries:
I’d be happy to test or contribute a small PR if guidance can be provided on the preferred direction for supporting custom primary key fields.
Beta Was this translation helpful? Give feedback.
All reactions