Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

side-effect on other modules using PyYAML #34

Open
ntoofu opened this issue Oct 7, 2017 · 2 comments
Open

side-effect on other modules using PyYAML #34

ntoofu opened this issue Oct 7, 2017 · 2 comments

Comments

@ntoofu
Copy link

ntoofu commented Oct 7, 2017

Following example script fails because yaml.add_representer function which is called in initialization of pyraml module (pyraml/__init__.py) changes behavior of PyYAML module. Modified PyYAML module will parse dictionary structure in YAML to UniqOrderedDict, so re-assignment to the data parsed by PyYAML will raise exception.

import pyraml
import yaml


if __name__ == '__main__':
    with open("test.yml") as f:
        data = yaml.load(f)

    print(data)
    data['key'] = "new_value"    # <= raise ValidationError
    print(data)

Result:

UniqOrderedDict([('key', 'value')])
Traceback (most recent call last):
  File "example.py", line 10, in <module>
    data['key'] = "new_value"
  File "/usr/local/lib/python2.7/site-packages/pyraml/__init__.py", line 24, in __setitem__
    raise ValidationError("Property already used: {0}".format(key))
pyraml.ValidationError: 'Property already used: key'

The exception is raised from the line below.

raise ValidationError("Property already used: {0}".format(key))

This problem is caused by design of yaml.add_representer in PyYAML module, but it may be better to modify pyraml-parser because PyYAML module is used widely and is hard to be changed.

@ntoofu ntoofu changed the title side-effect on other packages using PyYAML side-effect on other modules using PyYAML Oct 7, 2017
@jimconner
Copy link

I'm about four years late to this party, but wanted to say thanks for raising this issue as it helped me understand a problem I was having with pyraml-parser breaking PyYAML used in another place in the same code base. I worked around it by using ruyaml instead (leaving pyraml to have its monkey-patched PyYAML for itself).

@an2deg
Copy link
Owner

an2deg commented Apr 30, 2021

Hi @jimconner ,

Unfortunately I don't have time to maintain this project. The project is unmaintained for 4 or 5 years already.
Most probably I will put a banner that's the project is not maintaining anymore.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants