Skip to content

Fix: silent failure on entity update due to PK type mismatch#66

Open
dmazoli wants to merge 1 commit intobenavlabs:mainfrom
dmazoli:Bugfix-for-log_admin_action
Open

Fix: silent failure on entity update due to PK type mismatch#66
dmazoli wants to merge 1 commit intobenavlabs:mainfrom
dmazoli:Bugfix-for-log_admin_action

Conversation

@dmazoli
Copy link

@dmazoli dmazoli commented Feb 7, 2026

Hi there!

This is my first contribution to an open-source project, so please let me know if there is anything I should improve or change.

I implemented CRUDAdmin in a microservice at my company and encountered an issue where updating entities failed silently, redirecting back to the admin homepage.

I traced the error to the log_admin_action decorator. The issue occurred because my entity uses an integer as a Primary Key (PK), which was being passed directly in this line: item = await crud.get(db=db, id=kwargs["id"]).

In the query generated by fastcrud, the ID was being treated as a string, resulting in something like: SELECT {fields} FROM my_table WHERE id = var::CHAR.

I initially handled this with a monkey patch within my own project to keep things running, but I decided to contribute a proper fix. After discovering the _convert_id_to_pk_type method in the ModelView class, I moved it to the db file so it could be reused within the decorator.

I am also planning to contribute other features I've implemented in my project, such as the option to redirect back to the list view after creating an entity, and support for remote login without requiring a local user.

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

Successfully merging this pull request may close these issues.

1 participant