Navigation Menu

Skip to content
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

fix: func (schema *Schema) guessRelation(...) primaryFields are overwritten #5721

Merged
merged 1 commit into from Oct 7, 2022

Conversation

demoManito
Copy link
Member

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

What did this pull request do?

User Case Description

@demoManito demoManito force-pushed the fix/relationship/maybe-nil-panic branch 2 times, most recently from 118cf28 to 803bd1f Compare September 26, 2022 15:58
@jinzhu
Copy link
Member

jinzhu commented Sep 30, 2022

Hi @demoManito

can you add some tests that might reproduce the panic?

@demoManito
Copy link
Member Author

demoManito commented Sep 30, 2022

Hi @demoManito

can you add some tests that might reproduce the panic?

Hello @jinzhu

The else block redeclares primaryFields after appending, and appends data to it. The external primaryFields will not be modified. This is always empty, possibly index ou of:

primaryFields, foreignFields []*Field

var primaryFields []*Field

@demoManito demoManito force-pushed the fix/relationship/maybe-nil-panic branch from 803bd1f to 76941f3 Compare October 3, 2022 13:48
}
} else {
var primaryFields []*Field
Copy link
Member Author

Choose a reason for hiding this comment

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

This repeat and covered with the outer layer

Copy link
Member Author

Choose a reason for hiding this comment

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

See line 373

Copy link
Member Author

@demoManito demoManito Oct 3, 2022

Choose a reason for hiding this comment

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

This will cause the original 469 line to start, and the primaryKeys will always be empty

@demoManito demoManito changed the title fix relationship.go maybe nil panic fix: primaryFields are overwritten Oct 3, 2022
@jinzhu jinzhu merged commit 4b22a55 into go-gorm:master Oct 7, 2022
@demoManito demoManito changed the title fix: primaryFields are overwritten fix: func (schema *Schema) guessRelation(...) primaryFields are overwritten Oct 9, 2022
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.

None yet

2 participants