🛠️ fix(generator): fix map should not use default value for un null types - #31
🛠️ fix(generator): fix map should not use default value for un null types#31KiddoV wants to merge 1 commit into
Conversation
Summary of ChangesHello, 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 addresses a critical issue in the data generator where non-nullable types were incorrectly assigned default values during map deserialization, potentially leading to data integrity problems. It also significantly refines the handling of Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
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.
Code Review
This pull request correctly addresses an issue where default values were used for non-nullable types during deserialization from a map. Removing these default values is a great improvement for correctness, as it will now fail fast on missing data instead of silently using a default. The generalization of DateTime handling and the improved error handling in the date parsing function are also welcome changes. I have one suggestion to improve the readability and efficiency of the generated code for double and double? types by reducing code repetition.
| } else if (type == 'double') { | ||
| buffer.writeln( | ||
| " $fieldName: (map['$mapKey'] ?? map['${_camelToSnake(fieldName)}'] ?? 0.0) is int ? (map['$mapKey'] ?? map['${_camelToSnake(fieldName)}'] ?? 0.0).toDouble() : (map['$mapKey'] ?? map['${_camelToSnake(fieldName)}'] ?? 0.0) as double,", | ||
| " $fieldName: (map['$mapKey'] ?? map['${_camelToSnake(fieldName)}']) is int ? (map['$mapKey'] ?? map['${_camelToSnake(fieldName)}']).toDouble() : (map['$mapKey'] ?? map['${_camelToSnake(fieldName)}']) as double,", |
There was a problem hiding this comment.
The expression for handling double is quite repetitive. The sub-expression (map['$mapKey'] ?? map['${_camelToSnake(fieldName)}']) is evaluated up to three times. This makes the generated code less efficient and harder to read.
You could use an immediately-invoked function expression (IIFE) to store the value in a temporary variable and avoid repetition. This would also apply to the double? case on line 735.
| " $fieldName: (map['$mapKey'] ?? map['${_camelToSnake(fieldName)}']) is int ? (map['$mapKey'] ?? map['${_camelToSnake(fieldName)}']).toDouble() : (map['$mapKey'] ?? map['${_camelToSnake(fieldName)}']) as double,", | |
| " $fieldName: ((){ final v = map['$mapKey'] ?? map['${_camelToSnake(fieldName)}']; return v is int ? v.toDouble() : v as double; })()," |
|
This might be conflict and need to be resolved with PR #30 |
Related issue #29
I also add check for
DateTimeand DateTime?instead of just check forcreatedAtandmodifiedAt. AllDateTime` values should be treated the same.