ashb commented on a change in pull request #8637:
URL: https://github.com/apache/airflow/pull/8637#discussion_r418566928



##########
File path: airflow/configuration.py
##########
@@ -105,7 +106,6 @@ def default_config_yaml() -> dict:
     with open(file_path) as config_file:
         return yaml.safe_load(config_file)
 

Review comment:
       ```suggestion
   
   
   ```

##########
File path: tests/test_configuration.py
##########
@@ -440,33 +441,42 @@ def make_config():
             # lookup even if we remove this explicit fallback
             test_conf.deprecated_values = {
                 'core': {
-                    'task_runner': ('BashTaskRunner', 'StandardTaskRunner', 
'2.0'),
+                    'task_runner': (re.compile(r'\ABashTaskRunner\Z'), 
r'StandardTaskRunner', '2.0'),
+                    'hostname_callable': (re.compile(r':'), r'.', '2.0'),
                 },
             }
             test_conf.read_dict({
                 'core': {
                     'executor': 'SequentialExecutor',
                     'task_runner': 'BashTaskRunner',
                     'sql_alchemy_conn': 'sqlite://',
+                    'hostname_callable': 'socket:getfqdn',
                 },
             })
             return test_conf
 
         with self.assertWarns(FutureWarning):
             test_conf = make_config()
             self.assertEqual(test_conf.get('core', 'task_runner'), 
'StandardTaskRunner')
+            self.assertEqual(test_conf.get('core', 'hostname_callable'), 
'socket.getfqdn')
 
         with self.assertWarns(FutureWarning):
             with unittest.mock.patch.dict('os.environ', 
AIRFLOW__CORE__TASK_RUNNER='BashTaskRunner'):
                 test_conf = make_config()
 
                 self.assertEqual(test_conf.get('core', 'task_runner'), 
'StandardTaskRunner')
+
+            with unittest.mock.patch.dict('os.environ', 
AIRFLOW__CORE__HOSTNAME_CALLABLE='socket:getfqdn'):
+                test_conf = make_config()
+
+                self.assertEqual(test_conf.get('core', 'hostname_callable'), 
'socket.getfqdn')
         with reset_warning_registry():
             with warnings.catch_warnings(record=True) as warning:
-                with unittest.mock.patch.dict('os.environ', 
AIRFLOW__CORE__TASK_RUNNER='NotBashTaskRunner'):
+                with unittest.mock.patch.dict('os.environ', 
AIRFLOW__CORE__TASK_RUNNER='NotBashTaskRunner', 
AIRFLOW__CORE__HOSTNAME_CALLABLE='CarrierPigeon'):

Review comment:
       ```suggestion
                   with unittest.mock.patch.dict('os.environ',
                                                 
AIRFLOW__CORE__TASK_RUNNER='NotBashTaskRunner',
                                                 
AIRFLOW__CORE__HOSTNAME_CALLABLE='CarrierPigeon'):
   ```

##########
File path: airflow/configuration.py
##########
@@ -188,25 +189,36 @@ def _validate(self):
         for section, replacement in self.deprecated_values.items():
             for name, info in replacement.items():
                 old, new, version = info
-                if self.get(section, name, fallback=None) == old:
-                    # Make sure the env var option is removed, otherwise it
-                    # would be read and used instead of the value we set
-                    env_var = self._env_var_name(section, name)
-                    os.environ.pop(env_var, None)
-
-                    self.set(section, name, new)
-                    warnings.warn(
-                        'The {name} setting in [{section}] has the old default 
value '
-                        'of {old!r}. This value has been changed to {new!r} in 
the '
-                        'running config, but please update your config before 
Apache '
-                        'Airflow {version}.'.format(
-                            name=name, section=section, old=old, new=new, 
version=version
-                        ),
-                        FutureWarning
-                    )
+                current_value = self.get(section, name, fallback=None)
+                if self._using_old_value(old, current_value):
+                    new_value = re.sub(old, new, current_value)
+                    self._update_env_var(section=section, name=name, 
new_value=new_value)
+                    self._create_future_warning(name=name, section=section, 
current_value=current_value, new_value=new_value, version=version)

Review comment:
       ```suggestion
                       self._create_future_warning(name=name,
                                                   section=section,
                                                   current_value=current_value,
                                                   new_value=new_value,
                                                   version=version)
   ```




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