Skip to content

fix(generics): align Select signature with DB.Select#7760

Open
MichaelSatoshi1983 wants to merge 1 commit intogo-gorm:masterfrom
MichaelSatoshi1983:master
Open

fix(generics): align Select signature with DB.Select#7760
MichaelSatoshi1983 wants to merge 1 commit intogo-gorm:masterfrom
MichaelSatoshi1983:master

Conversation

@MichaelSatoshi1983
Copy link
Copy Markdown

  • [ - ] Do only one thing
  • [ - ] Non breaking API changes
  • [ - ] Tested

What did this pull request do?

Changed the Generics API Select signature from string to any so it matches DB.Select. This allows passing []string directly and fixes incorrect SQL generation when using dynamic field lists.

User Case Description

This fixes issue #7743 When the selected columns are built dynamically as []string, the previous Generics API required using Select("?", fields), which could generate incorrect SQL in PostgreSQL by treating column names as string literals. After this change, callers can use gorm.GUser.Select(fields) directly, consistent with the underlying API.

@propel-code-bot
Copy link
Copy Markdown
Contributor

Align generics Select signature with DB.Select and add array-input SQL regression test

This PR updates the generics API so Select accepts interface{} instead of string, matching the underlying DB.Select behavior. The change is applied consistently across the CreateInterface, ChainInterface, and both concrete implementations (createG and chainG) in generics.go.

A new test in tests/generics_test.go verifies that passing []string to gorm.G[User](tx).Select([]string{"id", "name"}) generates a proper column list SQL statement and does not render column names as string literals (e.g., ('id','name')). This directly addresses issue #7743 and validates the intended PostgreSQL-safe behavior for dynamic field lists.

Key Changes

• Changed Select method signatures from Select(query string, args ...interface{}) to Select(query interface{}, args ...interface{}) in CreateInterface[T] and ChainInterface[T] within generics.go.
• Updated concrete methods createG[T].Select and chainG[T].Select in generics.go to accept interface{} and forward to db.Select(query, args...).
• Added TestGenericsSelectWithArrayInput in tests/generics_test.go to validate SQL generation when Select receives []string.
• Test asserts both positive SQL shape (contains selected columns) and negative case (does not contain tuple-like string literals).

Affected Areas

generics.go
tests/generics_test.go
• Generics query-building API (CreateInterface[T], ChainInterface[T], createG[T], chainG[T])

This summary was automatically generated by @propel-code-bot

Copy link
Copy Markdown
Contributor

@propel-code-bot propel-code-bot Bot left a comment

Choose a reason for hiding this comment

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

No issues were identified; the signature alignment and added test appear consistent and appropriate.

Status: No Issues Found | Risk: Low

Review Details

📁 2 files reviewed | 💬 0 comments

@MichaelSatoshi1983
Copy link
Copy Markdown
Author

@jinzhu Please review,thanks

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