Skip to content

WIP: omitempty bug in InsertRecords#23

Closed
ScreamingHawk wants to merge 1 commit intogoware:masterfrom
ScreamingHawk:insertrecords
Closed

WIP: omitempty bug in InsertRecords#23
ScreamingHawk wants to merge 1 commit intogoware:masterfrom
ScreamingHawk:insertrecords

Conversation

@ScreamingHawk
Copy link
Copy Markdown

When you have a table with a field tagged omitempty, calling InsertRecords will fail if some records have empty values and some do not. The error is pgkit: 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.

@VojtechVitek
Copy link
Copy Markdown
Member

Hmm, I'm not sure why CI jobs didn't trigger.

Copy link
Copy Markdown
Member

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

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

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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line didn't cause the test to fail.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It was the batch INSERT statement that had created_at column value in the first record; but no value in the second.

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