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 2021/12/15 05:03:46 UTC
[GitHub] [airflow] uranusjr commented on a change in pull request #20174: Add deprecation warnining for non-json-serializable params
uranusjr commented on a change in pull request #20174:
URL: https://github.com/apache/airflow/pull/20174#discussion_r769243345
##########
File path: airflow/models/param.py
##########
@@ -49,10 +51,28 @@ def __init__(self, default: Any = NOTSET, description: Optional[str] = None, **k
self.description = description
self.schema = kwargs.pop('schema') if 'schema' in kwargs else kwargs
+ if self.has_value:
+ self._validate(self.value, self.schema)
+
+ @staticmethod
+ def _validate(value, schema):
+ """
+ 1. Check that value is json-serializable; if not, warn. In future release we will require
+ the value to be json-serializable.
+ 2. Validate ``value`` against ``schema``
+ """
+ try:
+ json.dumps(value)
+ except Exception:
+ warnings.warn(
+ "The use of non-json-serializable params is deprecated and will be removed in "
+ " a future release",
+ DeprecationWarning,
+ )
Review comment:
```suggestion
warnings.warn(
"The use of non-json-serializable params is deprecated and will be removed in "
"a future release",
DeprecationWarning,
)
```
Also I think we should add `stacklevel` to make the warning show where the user defines the params.
--
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