Skip to content

Commit

Permalink
[AIRFLOW-3742] Fix handling of "fallback" for AirflowConfigParsxer.ge…
Browse files Browse the repository at this point in the history
…tint/boolean (#4674)

We added (and used) fallback as an argument on `getboolean` but didn't
add it to the method, or add tests covering those "casting" accessors,
so they broke.

This fixes those methods, and adds tests covering them
  • Loading branch information
ttanay authored and ashb committed Feb 11, 2019
1 parent 59d2615 commit 8917ce6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
20 changes: 10 additions & 10 deletions airflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,27 +260,27 @@ def get(self, section, key, **kwargs):
"section/key [{section}/{key}] not found "
"in config".format(**locals()))

def getboolean(self, section, key):
val = str(self.get(section, key)).lower().strip()
def getboolean(self, section, key, **kwargs):
val = str(self.get(section, key, **kwargs)).lower().strip()
if '#' in val:
val = val.split('#')[0].strip()
if val.lower() in ('t', 'true', '1'):
if val in ('t', 'true', '1'):
return True
elif val.lower() in ('f', 'false', '0'):
elif val in ('f', 'false', '0'):
return False
else:
raise AirflowConfigException(
'The value for configuration option "{}:{}" is not a '
'boolean (received "{}").'.format(section, key, val))

def getint(self, section, key):
return int(self.get(section, key))
def getint(self, section, key, **kwargs):
return int(self.get(section, key, **kwargs))

def getfloat(self, section, key):
return float(self.get(section, key))
def getfloat(self, section, key, **kwargs):
return float(self.get(section, key, **kwargs))

def read(self, filenames):
super(AirflowConfigParser, self).read(filenames)
def read(self, filenames, **kwargs):
super(AirflowConfigParser, self).read(filenames, **kwargs)
self._validate()

def read_dict(self, *args, **kwargs):
Expand Down
5 changes: 4 additions & 1 deletion tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_conf_as_dict_raw(self):
self.assertEqual(cfg_dict['testsection']['testpercent'], 'with%%percent')
self.assertEqual(cfg_dict['core']['percent'], 'with%%inside')

def test_command_config(self):
def test_command_precedence(self):
TEST_CONFIG = '''[test]
key1 = hello
key2_cmd = printf cmd_result
Expand Down Expand Up @@ -170,6 +170,9 @@ def test_command_config(self):
self.assertEqual('hello', test_conf.get('test', 'key1', fallback='fb'))
self.assertEqual('value6', test_conf.get('another', 'key6', fallback='fb'))
self.assertEqual('fb', test_conf.get('another', 'key7', fallback='fb'))
self.assertEqual(True, test_conf.getboolean('another', 'key8_boolean', fallback='True'))
self.assertEqual(10, test_conf.getint('another', 'key8_int', fallback='10'))
self.assertEqual(1.0, test_conf.getfloat('another', 'key8_float', fallback='1'))

self.assertTrue(test_conf.has_option('test', 'key1'))
self.assertTrue(test_conf.has_option('test', 'key2'))
Expand Down

0 comments on commit 8917ce6

Please sign in to comment.