Skip to content

fix: handle sql.Null* types correctly in database wrapper generator - #744

Merged
kalbasit merged 4 commits into
mainfrom
02-05-fix_handle_sql.null_types_correctly_in_database_wrapper_generator
Feb 5, 2026
Merged

kalbasit merged 4 commits into
mainfrom
02-05-fix_handle_sql.null_types_correctly_in_database_wrapper_generator

Conversation

@kalbasit

@kalbasit kalbasit commented Feb 5, 2026 •

Copy link
Copy Markdown
Owner

The gen-db-wrappers tool was attempting to cast sql.NullInt64 and other
sql.Null* types using invalid function call syntax like sql.NullInt64(value).
This doesn't work because these are struct types, not types that can be cast
with simple function syntax.

Added an isStructType() helper function to detect sql.Null* types and modified
the type conversion logic in joinParamsCall() to avoid attempting function call
syntax casting for struct types. When both source and target types are struct
types, the value is now passed directly without casting.

This fixes the TotalChunks field generation issue where it was being incorrectly
cast in CreateNarFile and UpdateNarFileTotalChunks functions across all database
backends (SQLite, PostgreSQL, MySQL).

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working go Pull requests that update go code labels Feb 5, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @kalbasit, 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 rectifies a critical type casting error within the gen-db-wrappers tool, specifically concerning sql.Null* types. The tool previously attempted to cast these struct types using an invalid function call syntax, leading to compilation failures. The updated logic now intelligently identifies these struct types and performs direct assignments, ensuring the generated database wrapper code is syntactically correct and functional, thereby resolving issues related to field generation in database operations.

Highlights

  • sql.Null Type Handling*: The gen-db-wrappers tool now correctly handles sql.Null* types (e.g., sql.NullInt64) by avoiding invalid function call casting syntax.
  • New isStructType Helper: A new helper function, isStructType, has been introduced to identify struct types like sql.Null* that require special handling during code generation.
  • joinParamsCall Logic Update: The joinParamsCall function has been updated to use direct assignment for sql.Null* types when source and target types differ, instead of attempting an incorrect type cast.
  • Fix for TotalChunks Field: This change resolves issues with the TotalChunks field generation in CreateNarFile and UpdateNarFileTotalChunks functions across various database backends.
Changelog
  • nix/gen-db-wrappers/src/main.go
    • Modified the joinParamsCall function to include a new conditional branch that checks if the targetField.Type is a struct type using the newly introduced isStructType helper. If it is, direct assignment is used instead of attempting a type cast.
    • Added a new isStructType function that returns true for types prefixed with "sql.Null", indicating they are sql.Null* types from the database/sql package.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

kalbasit commented Feb 5, 2026 •

Copy link
Copy Markdown
Owner Author

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 correctly fixes a bug in the database wrapper generator that caused it to produce syntactically incorrect code for sql.Null* types. By introducing an isStructType helper and adjusting the code generation logic to perform direct assignment for these struct types, the fix prevents invalid casting syntax and correctly relies on the Go compiler to handle type checking. The changes are well-targeted and effective. I have one suggestion to slightly refactor the conditional logic for improved conciseness.

Comment thread nix/gen-db-wrappers/src/main.go Resolved
@kalbasit
kalbasit force-pushed the 02-05-fix_handle_sql.null_types_correctly_in_database_wrapper_generator branch from fa9de50 to efed176 Compare February 5, 2026 08:50
Base automatically changed from 02-04-refactor_improve_test_code_quality_in_distributed_cache_tests to main February 5, 2026 09:05
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Feb 5, 2026
The gen-db-wrappers tool was attempting to cast sql.NullInt64 and other
sql.Null* types using invalid function call syntax like sql.NullInt64(value).
This doesn't work because these are struct types, not types that can be cast
with simple function syntax.

Added an isStructType() helper function to detect sql.Null* types and modified
the type conversion logic in joinParamsCall() to avoid attempting function call
syntax casting for struct types. When both source and target types are struct
types, the value is now passed directly without casting.

This fixes the TotalChunks field generation issue where it was being incorrectly
cast in CreateNarFile and UpdateNarFileTotalChunks functions across all database
backends (SQLite, PostgreSQL, MySQL).
@kalbasit
kalbasit force-pushed the 02-05-fix_handle_sql.null_types_correctly_in_database_wrapper_generator branch from efed176 to 56ab810 Compare February 5, 2026 09:06
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Feb 5, 2026
@codecov

codecov Bot commented Feb 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.41%. Comparing base (178d094) to head (84ed23a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #744   +/-   ##
=======================================
  Coverage   85.41%   85.41%           
=======================================
  Files           2        2           
  Lines         480      480           
=======================================
  Hits          410      410           
  Misses         65       65           
  Partials        5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalbasit
kalbasit enabled auto-merge (squash) February 5, 2026 09:50
@kalbasit
kalbasit merged commit c91df8c into main Feb 5, 2026
15 checks passed
@kalbasit
kalbasit deleted the 02-05-fix_handle_sql.null_types_correctly_in_database_wrapper_generator branch February 5, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant