Repository: apache/airflow
File: shared/configuration/tests/configuration/test_parser.py (Python)

Code before:
                                "default": "some_value",
                                "deprecation_reason": "deprecated",
                            },
                            "deprecated_key2": {
                                "default": "some_value",
                                "version_deprecated": "2.0.0",
                            },
                            "active_key": {
                                "default": "active_value",
                            },
                        }
                    }
                }
                _default_values = ConfigParser()
                # verify configure_parser_from_configuration_description logic of skipping
                configure_parser_from_configuration_description(
                    _default_values, configuration_description, {}
                )
                _SharedAirflowConfigParser.__init__(self, configuration_description, _default_values)

        test_conf = TestConfigParser()

        # get_default_value should return fallback if not found
        expected_sentinel = object()
        assert (
            test_conf.get("test_section", "deprecated_key", fallback=expected_sentinel) is expected_sentinel
        )
        assert (
            test_conf.get("test_section", "deprecated_key2", fallback=expected_sentinel) is expected_sentinel
        )
        # Active key should be present
        assert test_conf.get("test_section", "active_key") == "active_value"


Review comment (suggestion):
Just the fact that it returns the `fallback`, means that it didn't find the deprecated key in the config as expected.

But `conf.get()` is usually used without a fallback. Can you add a check without it?

```python
test_conf.get("test_section", "deprecated_key")
```

Code after:
                                "default": "some_value",
                                "deprecation_reason": "deprecated",
                            },
                            "deprecated_key2": {
                                "default": "some_value",
                                "version_deprecated": "2.0.0",
                            },
                            "deprecated_key3": {
                                "default": None,
                                "version_deprecated": "2.0.0",
                            },
                            "active_key": {
                                "default": "active_value",
                            },
                        }
                    }
                }
                _default_values = ConfigParser()
                # verify configure_parser_from_configuration_description logic of skipping
                configure_parser_from_configuration_description(
                    _default_values, configuration_description, {}
                )
                _SharedAirflowConfigParser.__init__(self, configuration_description, _default_values)

        test_conf = TestConfigParser()
        deprecated_conf_list = [
            ("test_section", "deprecated_key"),
            ("test_section", "deprecated_key2"),
            ("test_section", "deprecated_key3"),
        ]

        # case 1: using `get` with fallback
        # should return fallback if not found
        expected_sentinel = object()
        for section, key in deprecated_conf_list:
            assert test_conf.get(section, key, fallback=expected_sentinel) is expected_sentinel

        # case 2: using `get` without fallback
        # should raise AirflowConfigException
        for section, key in deprecated_conf_list:
            with pytest.raises(
                AirflowConfigException,
                match=re.escape(f"section/key [{section}/{key}] not found in config"),
            ):
                test_conf.get(section, key)

        # case 3: active (non-deprecated) key
        # Active key should be present
        assert test_conf.get("test_section", "active_key") == "active_value"