WIP: omitempty bug in InsertRecords#23
Closed
ScreamingHawk wants to merge 1 commit intogoware:masterfrom
Closed
Conversation
VojtechVitek
approved these changes
Nov 5, 2024
Member
|
Hmm, I'm not sure why CI jobs didn't trigger. |
72b9263 to
14c748a
Compare
Member
VojtechVitek
left a comment
There was a problem hiding this comment.
Closing this PR.
The underlying issue is caused by different number of arguments to the INSERT statement caused by CreatedAt field.
| CREATE TABLE accounts ( | ||
| id SERIAL PRIMARY KEY, | ||
| name VARCHAR(255), | ||
| name VARCHAR(255) NOT NULL, |
Member
There was a problem hiding this comment.
This line didn't cause the test to fail.
Member
There was a problem hiding this comment.
It was the batch INSERT statement that had created_at column value in the first record; but no value in the second.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When you have a table with a field tagged
omitempty, callingInsertRecordswill fail if some records have empty values and some do not. The error ispgkit: ERROR: VALUES lists must all be the same length (SQLSTATE 42601).This is because the reflection (correctly) ignores the fields tagged
omitempty, which results in different fields being supplied for the insert statement.https://github.com/goware/pgkit/blob/master/builder.go#L51
https://github.com/goware/pgkit/blob/master/mapper.go#L41
NOTE: This PR is only to share the failing test case.