Fix: silent failure on entity update due to PK type mismatch#66
Open
dmazoli wants to merge 1 commit intobenavlabs:mainfrom
Open
Fix: silent failure on entity update due to PK type mismatch#66dmazoli wants to merge 1 commit intobenavlabs:mainfrom
dmazoli wants to merge 1 commit intobenavlabs:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.