Skip to content

Comments

fix: prevent some built-in drivers being overwritten#45

Merged
murfffi merged 1 commit intomainfrom
fix/alias
Mar 15, 2025
Merged

fix: prevent some built-in drivers being overwritten#45
murfffi merged 1 commit intomainfrom
fix/alias

Conversation

@murfffi
Copy link
Member

@murfffi murfffi commented Mar 15, 2025

Before this fix, mssql would incorrectly be replaced with a generic driver configuration, because it would appear as a new databases.

This fix also prevents the autogenerated two-letter alias to overwrite an exising alias.

Copy link
Contributor

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @murfffi, 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!

Summary of Changes

This pull request addresses an issue where built-in database drivers could be overwritten by new drivers with the same name or alias. Specifically, it prevents scenarios where mssql would be incorrectly replaced with a generic driver configuration. The fix also ensures that autogenerated two-letter aliases do not overwrite existing aliases. The changes involve modifying the driver registration logic to check for existing schemes and aliases before registering new ones.

Highlights

  • Driver Overwrite Prevention: Prevents built-in drivers from being overwritten by new drivers with the same name.
  • Alias Collision Avoidance: Ensures that autogenerated two-letter aliases do not overwrite existing aliases.
  • Scheme Registration Logic: Modifies the driver registration logic to check for existing schemes and aliases before registering new ones.

Changelog

Click here to see the changelog
  • internal/gen/dbmgr.go
    • Introduces existingSchemes to track existing driver schemes and aliases.
    • Adds initExistingSchemes to populate existingSchemes with base schemes and aliases.
    • Modifies findNew to use a set for efficient lookup of existing drivers.
    • Introduces toSet to convert a slice of strings to a set.
    • Updates RegisterNewDrivers to check against existingSchemes before registering new drivers.
    • Adds logging to indicate when no new drivers are found due to name clashes.
    • Updates getScheme to generate unique short aliases using getUniqueShortAlias.
    • Implements getUniqueShortAlias to find a unique two-letter alias for a driver, avoiding collisions with existing aliases.
    • Removes the unregistering of drivers and aliases before registering new ones, as this is no longer needed with the new logic.
  • internal/gen/gen_test.go
    • Adds a test case to verify that mssql is not incorrectly re-registered.
    • Updates the existing test case to check for the correct output format for MonetDB driver registration.
  • internal/integrationtest/monetdb/monetdb_test.go
    • Adds a test case to verify that the MonetDB driver can be accessed using its short alias (mo).
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.


A driver's plight, to find its place,
In a system vast, with schemes to chase.
No overwrite, no alias clash,
Just smooth connections, in a coding dash.

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.

Copy link
Contributor

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request aims to prevent built-in drivers from being overwritten and to avoid overwriting existing aliases with autogenerated two-letter aliases. The changes look good overall, but there are a few areas that could be improved for clarity and robustness.

Summary of Findings

  • Error Handling in getUniqueShortAlias: The getUniqueShortAlias function panics if it cannot generate a unique short alias. This could lead to unexpected application termination. Consider returning an error instead to allow for graceful handling.
  • Logging when no new drivers are found: The log message in RegisterNewDrivers when no new drivers are found could be more informative. It currently suggests driver name clashes, but it might be helpful to include potential causes or debugging steps.
  • Clarity of findNew function: The purpose of the findNew function could be clarified with a comment explaining its intent, especially regarding the use of slices.DeleteFunc.

Merge Readiness

The pull request addresses an important issue and the changes seem to be effective. However, the potential panic in getUniqueShortAlias should be addressed before merging. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. I recommend that the critical severity issue be addressed before merging.

@murfffi murfffi force-pushed the fix/alias branch 2 times, most recently from 4ba4d36 to 1b9ebd5 Compare March 15, 2025 16:47
Before this fix, mssql would incorrectly be replaced with a generic driver
configuration, because it would appear as a new databases.

This fix also prevents the autogenerated two-letter alias to overwrite an
exising alias.
@murfffi murfffi merged commit 855cd9a into main Mar 15, 2025
2 checks passed
@murfffi murfffi deleted the fix/alias branch March 15, 2025 17:19
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