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: improve inferred json encoding for csv output #364

Merged
merged 1 commit into from
Jan 22, 2021

Conversation

iand
Copy link
Contributor

@iand iand commented Jan 21, 2021

Nil JSON values should be encoded as lower-case null in the CSV output, but other nil values should remain uppercase

Slices and other non-scalar types are automatically inferred to be stored as JSON by go-pg so we can use that to automatically encode. However string types that have the type:jsonb annotation in our models refer to values that have already been encoded as JSON, so the CSV output needs to avoid encoding them again.

@iand iand self-assigned this Jan 21, 2021
@iand iand requested review from frrist and placer14 January 21, 2021 10:57
@codecov-io
Copy link

Codecov Report

Merging #364 (1b367bf) into master (52e5a9c) will increase coverage by 0.2%.
The diff coverage is 88.2%.

@@           Coverage Diff            @@
##           master    #364     +/-   ##
========================================
+ Coverage    42.7%   43.0%   +0.2%     
========================================
  Files          25      25             
  Lines        1907    1917     +10     
========================================
+ Hits          816     826     +10     
  Misses        964     964             
  Partials      127     127             


// Strings marked as json type are assumed to already be encoded
if fk != reflect.String && (t.types[i] == "json" || t.types[i] == "jsonb") {
encodeAsJSON = true
Copy link
Member

Choose a reason for hiding this comment

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

Should this be false if its already encoded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is checking if it has a json datatype but is not a string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment should be clearer

Comment on lines +202 to +204
} else if fk == reflect.Interface {
encodeAsJSON = true
}
Copy link
Member

@frrist frrist Jan 21, 2021

Choose a reason for hiding this comment

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

Does this mean slices of strings/bytes/structs will be encoded as json?

Copy link
Contributor Author

@iand iand Jan 22, 2021

Choose a reason for hiding this comment

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

Slices of strings encode as json. For example MultisigTransaction.Approved is a []string with no column type tag. go-pg assigns that a json type by default, which matches our schema. Same with MinerInfo.ControlAddresses and MinerInfo.MultiAddresses.

@iand iand merged commit a8c0304 into master Jan 22, 2021
@iand iand deleted the iand/csv-json-handling branch January 22, 2021 10:52
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.

3 participants