You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2023/01/09 02:22:20 UTC

[GitHub] [airflow] uranusjr commented on a diff in pull request #28777: Fix dag run conf encoding with non-JSON serializable values

uranusjr commented on code in PR #28777:
URL: https://github.com/apache/airflow/pull/28777#discussion_r1064247537


##########
airflow/www/utils.py:
##########
@@ -133,13 +133,25 @@ def get_mapped_summary(parent_instance, task_instances):
 
 
 def get_dag_run_conf(dag_run_conf: Any) -> tuple[str | None, bool]:
+    class DagRunConfEncoder(json.JSONEncoder):
+        def default(self, obj):
+            if isinstance(obj, bytes):
+                try:
+                    return obj.decode()
+                except Exception:
+                    return str(obj)
+            try:
+                return json.JSONEncoder.default(self, obj)
+            except Exception:
+                return str(obj)

Review Comment:
   Just to comment, if you _have_ to stringify things for display, `repr` is better than `str`.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org