Skip to content

fix(schema): check the hook function parameter type #7468

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

Merged
merged 3 commits into from
Jul 21, 2025

Conversation

demoManito
Copy link
Member

@demoManito demoManito commented May 29, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

User Case Description

@demoManito demoManito changed the title fix(schema): Check the callback function parameter type fix(schema): check the callback function parameter type May 29, 2025
@demoManito demoManito changed the title fix(schema): check the callback function parameter type fix(schema): check the hook function parameter type May 29, 2025
@demoManito demoManito requested a review from Copilot May 30, 2025 11:20
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves hook function validation by ensuring that the hook functions in models have the correct parameter type. The change adds a runtime check that verifies the package path of the hook's first parameter and logs a warning if it doesn't match the expected type.

  • Adds a check to verify that the hook function parameter is from the "gorm.io/gorm" package.
  • Logs a warning when the hook function parameter type is incorrect.
Comments suppressed due to low confidence (1)

schema/schema.go:317

  • Consider returning an error instead of only logging a warning when the hook function parameter type is incorrect. This change would enforce the expected contract and help prevent silent misconfigurations.
if inVarPkg := methodValue.Type().In(0).Elem().PkgPath(); inVarPkg != "gorm.io/gorm" {

@go-gorm go-gorm deleted a comment from Copilot AI May 30, 2025
@jinzhu jinzhu merged commit b9c7e56 into go-gorm:master Jul 21, 2025
25 checks passed
@demoManito demoManito deleted the fix/callback-check branch July 21, 2025 10:27
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.

2 participants