-
Notifications
You must be signed in to change notification settings - Fork 454
Add logging for GORM expression in stateMap and dynamicJSON #395
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
base: main
Are you sure you want to change the base?
Conversation
This commit adds logging of the expression result in `GormValue` for both `stateMap` and `dynamicJSON` types in `session/database/gorm_datatypes.go`. It uses `db.Logger.Info` to log the result if a logger is configured. This resolves the TODOs in the code.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @sheing-google, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request improves the debuggability and observability of GORM operations within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds logging for GORM expression values as intended, resolving the TODOs in the code. The implementation is straightforward. However, I've pointed out a high-severity issue in stateMap.GormValue where a potential error from json.Marshal is ignored. This could lead to silent failures and incorrect database operations. While the change itself is correct in adding logging, it misses an opportunity to make the code more robust by handling this error.
This commit adds logging of the expression result in `GormValue` for both `stateMap` and `dynamicJSON` types in `session/database/gorm_datatypes.go`. It uses `db.Logger.Info` to log the result if a logger is configured. It also logs an error if `json.Marshal` fails during `GormValue`. This resolves the TODOs in the code.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds logging for GORM expression generation in stateMap and dynamicJSON types, resolving a TODO. The implementation for dynamicJSON is correct. However, the implementation for stateMap could lead to silent data loss if json.Marshal fails. I've provided a review comment with a suggestion to refactor the logic to handle marshalling errors more robustly by returning a NULL expression, which also simplifies the code structure. Overall, a good improvement with that one correction.
| data, err := json.Marshal(sm) | ||
| if db.Logger != nil { | ||
| if err != nil { | ||
| db.Logger.Error(ctx, "GormValue json.Marshal error: %v", err) | ||
| } else { | ||
| db.Logger.Info(ctx, "GormValue expression result: %s", string(data)) | ||
| } | ||
| } | ||
| return gorm.Expr("?", string(data)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While adding logging is great, the current implementation has a potential issue. If json.Marshal fails, the error is logged, but the function proceeds to return gorm.Expr("?", "") because data will be nil. This results in an empty string being stored in the database, which might mask the marshalling error. It would be more robust to handle the error explicitly and return a NULL expression, which is a clearer representation of failed data generation. This also simplifies the logic by removing nested if statements.
data, err := json.Marshal(sm)
if err != nil {
if db.Logger != nil {
db.Logger.Error(ctx, "GormValue json.Marshal error: %v", err)
}
return gorm.Expr("NULL")
}
if db.Logger != nil {
db.Logger.Info(ctx, "GormValue expression result: %s", string(data))
}
return gorm.Expr("?", string(data))
This commit adds logging of the expression result in
GormValuefor bothstateMapanddynamicJSONtypes insession/database/gorm_datatypes.go. It usesdb.Logger.Infoto log the result if a logger is configured. This resolves the TODOs in the code.