ashb commented on a change in pull request #7281: [AIRFLOW-5843] Add conf
option to Add DAG Run view
URL: https://github.com/apache/airflow/pull/7281#discussion_r372651034
##########
File path: airflow/www/validators.py
##########
@@ -56,3 +58,23 @@ def __call__(self, form, field):
message = message % d
raise ValidationError(message)
+
+
+class ValidJson(object):
+ """Validates data is valid JSON.
+
+ :param message:
+ Error message to raise in case of a validation error.
+ """
+ def __init__(self, message=None):
+ self.message = message
+
+ def __call__(self, form, field):
+ if field.data:
+ try:
+ json.loads(field.data)
+ except Exception:
+ message = self.message or "{} is not valid JSON"
+ raise ValidationError(
+ message=field.gettext(message.format(field.data))
Review comment:
This message might be very long -- I don't know how exactly it's rendered,
but I think including the content of the exception (from line 76) might be more
useful -- for example that is `'Expecting value: line 3 column 1 (char 3)'`
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services