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
refactor(pg): store nil map as empty {} #6929
refactor(pg): store nil map as empty {} #6929
Conversation
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
Images are ready for the commit at 7d1d2f6. To use with deploy scripts, first |
What about all the preexisting entries in the DB using the old format? |
I think they are fine. Queries will be the same a before and will work, when upsert will happen we will replace them with |
If we change all the values to {}, will pgx v4 still work the same way? We need to ensure any changes are completely backwards compatible |
That's tricky. If we want be 100% backward compatible then we should store The only incompatibility I could think of is a query that checks exact value or if value is a string and not map. I think our code does not allow such queries but I'm not an expert in this area. @md2119 do we expose any other queries than tested for maps? |
We pretty much have to be backwards compatible in the event of a rollback from 4.2 to 4.1. Greatly increases the amount of testing required to verify that we can make this change. |
26a47a2
to
bea289d
Compare
@connorgorman @dashrews78 I added test for this behaviour and changed from |
2ad6341
to
8f85554
Compare
bea289d
to
da0fb0b
Compare
/retest |
8f85554
to
e6bb503
Compare
da0fb0b
to
baad7ef
Compare
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.
please ensure value array construction consistency across insertInto
and copyFrom
@@ -205,6 +205,8 @@ func {{ template "insertFunctionName" $schema }}({{ if eq (len $schema.Children) | |||
pgutils.NilOrTime({{$field.Getter "obj"}}), | |||
{{- else if eq $field.SQLType "uuid" }} | |||
pgutils.NilOrUUID({{$field.Getter "obj"}}), | |||
{{- else if eq $field.DataType "map" }} | |||
pgutils.EmptyOrMap({{$field.Getter "obj"}}), |
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.
I think the copyFrom template needs this change too (at least to be future-proof).
Maybe the {{- range $field := $schema.DBColumnFields -}} ... {{- end }}
pattern could be extracted into another template.
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.
oh, good point. I'll try to add a test for it too
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.
baad7ef
to
f688304
Compare
/retest |
f688304
to
7ccf79d
Compare
7ccf79d
to
7d1d2f6
Compare
/retest |
## Description Fixes: - #6929 (comment) ## Checklist - [ ] Investigated and inspected CI test results - [ ] Unit test and regression tests added - [ ] Evaluated and added CHANGELOG entry if required - [ ] Determined and documented upgrade steps - [ ] Documented user facing changes (create PR based on [openshift/openshift-docs](https://github.com/openshift/openshift-docs) and merge into [rhacs-docs](https://github.com/openshift/openshift-docs/tree/rhacs-docs)) If any of these don't apply, please comment below. ## Testing Performed CI
Description
Currently we store nil map as
'null'
(string). In next version of pgx the semantic has changed and it will be stored asnull
.This PR seal this behaviour and whenever we would like to store nil map it will be replaced with
{}
(empty but not nil map).TestIndex/TestMapHighlights/key_does_not_exist
shows the difference between having'null'
andnull
in JSON field and null always returns false so negative queries will not work correctly.Checklist
If any of these don't apply, please comment below.
Testing Performed
CI