-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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(create): fix insert column order #6855
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some unit tests to describe what is being fixed?
add a ut case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order of defaultValueFieldsHavingValue
elements is based on FieldsWithDefaultDBValue
. https://github.com/go-gorm/gorm/pull/6855/files#diff-7539aa7c170a85138fa67c7846b65fda95a51169bcf8637d5961ea570307d755R284
I don't understand why the order needs to be maintained here again, and the unit test passed before the change, can you describe why we need it?
the type of defaultValueFieldsHavingValue is a map. before the change, column values is appended by iterating a map, which is not in a stable order. after the change, column values is appended following the order of FieldsWithDefaultDBValue, which is in stable order. |
Hi @archever, Thank you for your PR. Could you please remove those dependencies in go.mod? We aim to keep GORM's dependencies clean and tidy.
|
@jinzhu done |
t.Errorf("parse schema error: %v, is not expected", err) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use t.Fatalf
What did this pull request do?
make insert sql column order stable for unittest
User Case Description
gorm create() interface generated sql not stable for each test run. I changed the map interater to a stable slice in order to keep the column order.