jedcunningham commented on a change in pull request #21816:
URL: https://github.com/apache/airflow/pull/21816#discussion_r815239416



##########
File path: airflow/models/connection.py
##########
@@ -134,10 +134,32 @@ def __init__(
             self.schema = schema
             self.port = port
             self.extra = extra
+        if self.extra:
+            self._validate_extra(self.extra, self.conn_id)
 
         if self.password:
             mask_secret(self.password)
 
+    @staticmethod
+    def _validate_extra(extra, conn_id):
+        try:
+            _extra_parsed = json.loads(extra)
+            if not isinstance(_extra_parsed, dict):
+                warnings.warn(
+                    "Encountered JSON value in `extra` which does not parse as 
a dictionary in "
+                    f"connection {conn_id!r}. From Airflow 3.0, the `extra` 
field must contain a JSON "
+                    "representation of a python dict.",
+                    DeprecationWarning,
+                    stacklevel=2,

Review comment:
       ```suggestion
                       stacklevel=3,
   ```
   
   I think this is the right level?

##########
File path: airflow/models/connection.py
##########
@@ -134,10 +134,32 @@ def __init__(
             self.schema = schema
             self.port = port
             self.extra = extra
+        if self.extra:
+            self._validate_extra(self.extra, self.conn_id)
 
         if self.password:
             mask_secret(self.password)
 
+    @staticmethod
+    def _validate_extra(extra, conn_id):
+        try:
+            _extra_parsed = json.loads(extra)
+            if not isinstance(_extra_parsed, dict):

Review comment:
       ```suggestion
               extra_parsed = json.loads(extra)
               if not isinstance(extra_parsed, dict):
   ```
   
   nit: locally scoped, doesn't need to be private.




-- 
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]


Reply via email to