[FIX] openupgrade_merge_records: safely merge jsonb and serialized fields#425
Open
xaviedoanhduy wants to merge 2 commits intoOCA:masterfrom
Open
[FIX] openupgrade_merge_records: safely merge jsonb and serialized fields#425xaviedoanhduy wants to merge 2 commits intoOCA:masterfrom
xaviedoanhduy wants to merge 2 commits intoOCA:masterfrom
Conversation
076d391 to
35d9d6e
Compare
Member
|
@MiquelRForgeFlow Why are you asking me for a review without reviewing yourself? |
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 merging records using
openupgrade_merge_records.merge_records(),the helper
apply_operations_by_field_typeattempted to apply the|=operator directly on string values. however jsonb fields may be wrapped types (e.g. psycopg2.extras.Json), causing:TypeError: unsupported operand type(s) for |=: 'dict' and 'str'maybe not as expected the result returned like
method="sql"(ref), will return dict value like{"en_US": "Awaiting"}. but unfortunately inmethod="orm"even thoughnamefield in database is jsonb but in ORM level it is stillChartype and return a string like "Awaiting" so the error occurred.this proposed fix will convert string value to dict based on current language (mostly
en_US). In case field type isSerialized, the old logic remains the same because they are mostlydicts. And in python versions like3.8it seems that the|=operator is not supported yet so I replaced it with the.update()functionon this occasion also corrected the warning sush as:
UserWarning: unsupported operand type(s) for "==": 'res.company()' == '1'in the second commit 96be2e9