Skip to content

Commit

Permalink
Fix a bug in config. None was getting converted to "None"
Browse files Browse the repository at this point in the history
This broke out available_models API which checked for None.
  • Loading branch information
scosman committed Nov 12, 2024
1 parent 26a31a2 commit dd00db3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libs/core/kiln_ai/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def __getattr__(self, name: str) -> Any:

# Check if the value is in settings
if name in self._settings:
return property_config.type(self._settings[name])
value = self._settings[name]
return value if value is None else property_config.type(value)

# Check environment variable
if property_config.env_var and property_config.env_var in os.environ:
Expand All @@ -110,7 +111,7 @@ def __getattr__(self, name: str) -> Any:
else:
value = property_config.default

return property_config.type(value)
return None if value is None else property_config.type(value)

def __setattr__(self, name, value):
if name in ("_properties", "_settings"):
Expand Down
7 changes: 7 additions & 0 deletions libs/core/kiln_ai/utils/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def config_with_yaml(mock_yaml_file):
str, default="default_value", env_var="EXAMPLE_PROPERTY"
),
"int_property": ConfigProperty(int, default=0),
"empty_property": ConfigProperty(str),
}
)

Expand Down Expand Up @@ -67,6 +68,12 @@ def test_nonexistent_property(config_with_yaml):
config.nonexistent_property


def test_nonexistent_property_get_value(config_with_yaml):
config = config_with_yaml
assert config.get_value("nonexistent_property") is None
assert config.get_value("empty_property") is None


def test_property_type_conversion(config_with_yaml):
config = config_with_yaml
config = Config(properties={"int_property": ConfigProperty(int, default="42")})
Expand Down

0 comments on commit dd00db3

Please sign in to comment.