soltanianalytics commented on a change in pull request #13640:
URL: https://github.com/apache/airflow/pull/13640#discussion_r556164253



##########
File path: airflow/www/views.py
##########
@@ -2894,9 +2894,13 @@ def action_muldelete(self, items):
 
     def process_form(self, form, is_created):
         """Process form data."""
-        formdata = form.data
-        if formdata['conn_type'] in ['jdbc', 'google_cloud_platform', 'grpc', 
'yandexcloud', 'kubernetes']:
-            extra = {key: formdata[key] for key in self.extra_fields if key in 
formdata}
+        conn_type = form.data['conn_type']
+        extra = {
+            key: form.data[key]
+            for key in self.extra_fields
+            if key in form.data and key.startswith(f"extra__{conn_type}__")

Review comment:
       This assumes that the key already exists in `form.data`. (`if key in 
form.data ...`)
   
   In `prefill_form` below, this may not necessarily the case?
   
   

##########
File path: airflow/www/views.py
##########
@@ -2894,9 +2894,13 @@ def action_muldelete(self, items):
 
     def process_form(self, form, is_created):
         """Process form data."""
-        formdata = form.data
-        if formdata['conn_type'] in ['jdbc', 'google_cloud_platform', 'grpc', 
'yandexcloud', 'kubernetes']:
-            extra = {key: formdata[key] for key in self.extra_fields if key in 
formdata}
+        conn_type = form.data['conn_type']
+        extra = {
+            key: form.data[key]
+            for key in self.extra_fields
+            if key in form.data and key.startswith(f"extra__{conn_type}__")

Review comment:
       ```Python
       def prefill_form(self, form, pk):
           """Prefill the form."""
           try:
               extra = form.data.get('extra')
               if extra is None:
                   extra_dictionary = {}
               else:
                   extra_dictionary = json.loads(extra)
           except JSONDecodeError:
               extra_dictionary = {}
           if not isinstance(extra_dictionary, dict):
               logging.warning('extra field for %s is not a dictionary', 
form.data.get('conn_id', '<unknown>'))
               return
           for field in self.extra_fields:
               value = extra_dictionary.get(field, '')
               if value:  # !! This only adds data for the form.field if it 
previously exists in the extra
                   field = getattr(form, field)
                   field.data = value
   ```
   -> could it be that hence, the `form.data` does not contain the keys for the 
extra widgets?
   
   Generally, shouldnt `process_form` and `prefill_form` be analogous? From 
`prefill_form`, I could imagine something along those lines:
   
   ```Python
       def process_form(self, form, is_created):
           """Process form data."""
           conn_type = form.data['conn_type']
           extra = {
               key: getattr(form, key).data
               for key in self.extra_fields
               if hasattr(form, key) and 
key.startswith(f"extra__{conn_type}__") and getattr(form, key).data
           }
           if extra.keys():
               form.extra.data = json.dumps(extra)
   ```




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


Reply via email to