-
Notifications
You must be signed in to change notification settings - Fork 510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow empty YAML fields #1890
Allow empty YAML fields #1890
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @iojw. A nit. Consider adding a unit test to ensure this doesn’t break in the future?
sky/data/storage.py
Outdated
@@ -766,6 +766,7 @@ def warn_for_git_dir(source: str): | |||
|
|||
@classmethod | |||
def from_yaml_config(cls, config: Dict[str, Any]) -> 'Storage': | |||
config = {k: v for k, v in config.items() if v is not None} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible to move this into backend_utils.validate_schema since there are three places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a flag so we can enable this for validation. The reason we don't want to do it for all cases is that it prevents us from actually having null values in the schema in the future.
In addition, a lot of the current code relies on the fact that if a key exists in the config dictionary, then the value is valid. E.g. if we allow None to be inside the config dictionary, then inside storage.from_yaml_config
, force_delete = config.pop('_force_delete', False)
would incorrectly set force_delete
to None if the user specifies force_delete
in the YAML without a value. Therefore, I also had to refactor the code such that it properly handle None
config values.
Have we ensured that for all fields in the current YAML spec, None means absence means default value? Any cases where None means something else? |
@concretevitamin Yes, I've looked through |
c150bd4
to
7b78873
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, some questions.
sky/backends/backend_utils.py
Outdated
@@ -2471,7 +2471,10 @@ def stop_handler(signum, frame): | |||
raise KeyboardInterrupt(exceptions.SIGTSTP_CODE) | |||
|
|||
|
|||
def validate_schema(obj, schema, err_msg_prefix=''): | |||
def validate_schema(obj, schema, err_msg_prefix='', skip_none=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When do we want skip_none=False? In cli.py’s admin_deploy()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want it in cases where None
is a valid value for some config we are validating. After thinking about it further, it makes more sense to set the default to True
, since it is likelier than we want to remove None
values than not. I've updated to code for this.
@iojw Oops, slipped through the radar. Could you merge with master first? |
@concretevitamin Updated! |
LGTM. With the latest commit,
These tests failed, most likely due to merge conflicts. See comment: https://github.com/skypilot-org/skypilot/pull/1636/files#r1220710715 Could you merge again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @iojw.
Confirmed that smoke tests pass with these changes. |
Users may often comment out the nested contents of YAML fields without remove the top-level field. Previously, this would throw the following error due to our YAML validation:
This PR updates it so that such fields are treated as though they do not exist. It does this by removing all fields with a
None
value in the parsed dictionary before validation.We do not solve this issue by adding
null
to the JSON schema for our YAML config because many places in the code test for the existence of specific fields in the dictionary so we would have to modify all of their logic. Moreover, having to addnull
to every single field in the JSON schema reduces readability.Tested (run the relevant ones):
pytest tests/test_smoke.py
pytest tests/test_smoke.py::test_fill_in_the_name
bash tests/backward_comaptibility_tests.sh