PyYAML 4.1 changes "safe" in more ways than immediately obvious
See original GitHub issueIt’s clear from the changelog that pyyaml 4.x now defaults to a style of safe_load for loading. This is probably good. However, it also appears that the definition of “safe” has changed somewhat.
In https://github.com/cdent/gabbi/pull/252 the ‘safe’ related tests work differently depending on whether >4 or <4 is used. As currently written they pass with 4 and fail with 3. The difference seems to be that “safe” in 3 and 4 mean different things:
- in 4, safe will load custom tags that are defined in the same process, but not
python/object
, and unsafe will not load custom tags, but will loadpython/object
- in 3, custom tags only load in unsafe, and
python/object
, neither in safe
The branch on that pull request can demonstrate the problem with different PyYAML versions. And master in the same repo will as well.
However, I have no confidence that I’m parsing what’s going on properly at all, so I need to come up with a minimal test case, which I’ll try to do real soon, but I first wanted to get this written down in case there is something obviously wrong in either my code or in PyYAML.
I will followup to this with the MTC, ASAP. Sorry for dropping noise like this, but needed to dump state.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
This is a problem for me as well safe load working for custom tags, but not python objects: eg:
danger load works for python objects, but not for custom tags
PyYAML 5.1 is released now. https://pypi.org/project/PyYAML/5.1/
See https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation for safety details.