uranusjr commented on code in PR #69064:
URL: https://github.com/apache/airflow/pull/69064#discussion_r3484443939
##########
airflow-core/src/airflow/migrations/versions/0055_3_0_0_remove_pickled_data_from_dagrun_table.py:
##########
@@ -95,7 +118,12 @@ def upgrade():
try:
original_data = pickle.loads(pickle_data)
- json_data = json.dumps(original_data)
+ # Sanitize values legal in pickle but illegal in strict
JSON/JSONB so the
+ # row is preserved instead of dropped by the except below:
+ # * NaN / Infinity / -Infinity -> quoted strings (see
_json_safe).
+ # * the U+0000 (NUL) escape that json.dumps emits for
null bytes -> stripped
+ # (PostgreSQL JSON/JSONB cannot store it and it cannot
be quoted/kept).
+ json_data =
json.dumps(_json_safe(original_data)).replace('\\u0000', '')
Review Comment:
This would incorrectly replace genuinely escaped strings too (say `{"key":
"foo\\u0000bar"}`. An edge case, but regardless. Maybe this can do the fixing
before dumping instead? (or maybe that would be too costly since you’d need to
recursively find `str`s)
Alternatively, maybe it would be possible to use a regex? I am not entirely
sure. (Nor whether that would be more performant than reecursively fix strings
before dumping.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]