FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

refactor(pg): store nil map as empty {} by janisz · Pull Request #6929 · stackrox/stackrox · GitHub

refactor(pg): store nil map as empty {} - #6929

Merged
janisz merged 1 commit into
masterfrom
master-janisz/07-13-refactor_pg_store_empty_map_as_not_null
Jul 26, 2023
Merged

refactor(pg): store nil map as empty {}#6929
janisz merged 1 commit into
masterfrom
master-janisz/07-13-refactor_pg_store_empty_map_as_not_null

Conversation

janisz commented Jul 13, 2023
edited
Loading

Copy link
Copy Markdown
Contributor

Description

Currently we store nil map as 'null' (string). In next version of pgx the semantic has changed and it will be stored as null.
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' and null in JSON field and null always returns false so negative queries will not work correctly.

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 and merge into rhacs-docs)

If any of these don't apply, please comment below.

Testing Performed

CI

janisz requested a review from a team July 13, 2023 17:07

janisz commented Jul 13, 2023
edited
Loading

Copy link
Copy Markdown
Contributor Author

janisz requested a review from a team July 13, 2023 17:13
janisz changed the title refactor(pg): store empty map as {} not null refactor(pg): store nil map as empty; not null Jul 13, 2023

ghost commented Jul 13, 2023
edited by ghost
Loading

Copy link
Copy Markdown

Images are ready for the commit at 7d1d2f6.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.1.x-525-g7d1d2f6084.

janisz requested a review from connorgorman July 13, 2023 17:26

Copy link
Copy Markdown
Contributor

What about all the preexisting entries in the DB using the old format?

janisz commented Jul 13, 2023

Copy link
Copy Markdown
Contributor Author

What about all the pre existing 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 {}. I thought about using v4 approach and store 'null' but this doesn't make much sense.

Copy link
Copy Markdown
Contributor

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

janisz commented Jul 13, 2023

Copy link
Copy Markdown
Contributor Author

That's tricky. If we want be 100% backward compatible then we should store 'null'.

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?

Copy link
Copy Markdown
Collaborator

That's tricky. If we want be 100% backward compatible then we should store 'null'.

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.

janisz force-pushed the master-janisz/07-13-refactor_pg_store_empty_map_as_not_null branch from 26a47a2 to bea289d Compare July 14, 2023 11:32
janisz changed the base branch from master to master-janisz/07-14-test_pg_add_test_for_nil_map_serialisation July 14, 2023 11:32
janisz changed the title refactor(pg): store nil map as empty; not null refactor(pg): store nil map as 'null' Jul 14, 2023

janisz commented Jul 14, 2023
edited
Loading

Copy link
Copy Markdown
Contributor Author

@connorgorman @dashrews78 I added test for this behaviour and changed from {} to 'null'

janisz force-pushed the master-janisz/07-14-test_pg_add_test_for_nil_map_serialisation branch from 2ad6341 to 8f85554 Compare July 14, 2023 12:18
janisz force-pushed the master-janisz/07-13-refactor_pg_store_empty_map_as_not_null branch from bea289d to da0fb0b Compare July 14, 2023 12:19
janisz mentioned this pull request Jul 14, 2023
5 tasks

janisz commented Jul 17, 2023

Copy link
Copy Markdown
Contributor Author

/retest

janisz requested a review from dashrews78 July 18, 2023 10:50
janisz force-pushed the master-janisz/07-14-test_pg_add_test_for_nil_map_serialisation branch from 8f85554 to e6bb503 Compare July 20, 2023 11:16
Base automatically changed from master-janisz/07-14-test_pg_add_test_for_nil_map_serialisation to master July 24, 2023 11:05
janisz changed the title refactor(pg): store nil map as 'null' refactor(pg): store nil map as empty {} Jul 24, 2023
janisz force-pushed the master-janisz/07-13-refactor_pg_store_empty_map_as_not_null branch from da0fb0b to baad7ef Compare July 24, 2023 16:20

rhybrillou left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

please ensure value array construction consistency across insertInto and copyFrom

{{- else if eq $field.SQLType "uuid" }}
pgutils.NilOrUUID({{$field.Getter "obj"}}),
{{- else if eq $field.DataType "map" }}
pgutils.EmptyOrMap({{$field.Getter "obj"}}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

oh, good point. I'll try to add a test for it too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

janisz force-pushed the master-janisz/07-13-refactor_pg_store_empty_map_as_not_null branch from baad7ef to f688304 Compare July 25, 2023 10:45
janisz requested a review from rhybrillou July 25, 2023 10:45

janisz commented Jul 25, 2023

Copy link
Copy Markdown
Contributor Author

/retest

janisz force-pushed the master-janisz/07-13-refactor_pg_store_empty_map_as_not_null branch from f688304 to 7ccf79d Compare July 25, 2023 16:19
janisz force-pushed the master-janisz/07-13-refactor_pg_store_empty_map_as_not_null branch from 7ccf79d to 7d1d2f6 Compare July 25, 2023 18:27

janisz commented Jul 26, 2023

Copy link
Copy Markdown
Contributor Author

/retest

janisz commented Jul 26, 2023

Copy link
Copy Markdown
Contributor Author

@janisz started a stack merge that includes this pull request via Graphite.

janisz merged commit 42f13d8 into master Jul 26, 2023

janisz commented Jul 26, 2023

Copy link
Copy Markdown
Contributor Author

@janisz merged this pull request with Graphite.

janisz deleted the master-janisz/07-13-refactor_pg_store_empty_map_as_not_null branch July 26, 2023 09:15
janisz added a commit that referenced this pull request Jul 26, 2023
## 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
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL