Skip to content
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

DM-18906: Use safe YAML loading in verify #43

Merged
merged 1 commit into from
Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/lsst/verify/yamlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def load_all_ordered_yaml(stream, **kwargs):
return yaml.load_all(stream, OrderedLoader)


def _build_ordered_loader(Loader=yaml.Loader, object_pairs_hook=OrderedDict):
def _build_ordered_loader(Loader=yaml.CSafeLoader,
object_pairs_hook=OrderedDict):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that this ordered dict code is no longer needed since python3.7 guarantees dicts are ordered. The main problem with yaml is that on write it forces key sort (which can be disabled with sort_keys=False)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be. I'm not sure how to check that a rewrite wouldn't have ill effects, and I agree that it's out of scope.

# Solution from http://stackoverflow.com/a/21912744

class OrderedLoader(Loader):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
yaml_path = os.path.join(os.path.dirname(__file__),
'data', 'metrics', 'testing.yaml')
with open(yaml_path) as f:
self.metric_doc = yaml.load(f)
self.metric_doc = yaml.safe_load(f)

def test_load_all_yaml_metrics(self):
"""Verify that all metrics from testing.yaml can be loaded."""
Expand Down