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

ruamel.yaml 0.18 hard deprecated old PyYAML functions including load, safe_load, etc (scan, parse, compose, load, emit, serialize, dump and their variants _all, safe_, round_trip_, etc) #668

Closed
lathiat opened this issue Oct 24, 2023 · 3 comments

Comments

@lathiat
Copy link

lathiat commented Oct 24, 2023

My older stable charm builds using charm-tools 2.8.x broke today due to the release of ruamel.yaml 0.18

As noted here https://pypi.org/project/ruamel.yaml/

As announced, in 0.18.0, the old PyYAML functions have been deprecated. (scan, parse, compose, load, emit, serialize, dump and their variants (all, safe, round_trip_, etc)). If you only read this after your program has stopped working: I am sorry to hear that, but that also means you, or the person developing your program, has not tested with warnings on (which is the recommendation in PEP 565, and e.g. defaultin when using pytest).

In the OpenStack charm builds particularly, the error doesn't actually surface for some reason. The charm-build process just exits with an error code but no message. I had to use python -m trace to find the code throwing the error.

We use safe_load in many places but the place it errors out for me in particular is from charmtools/build/config.py:57 BuildConfig.configure()

We'll likely need to pin to ruamel.yaml<0.18.0 in the short term, for both 2.8.x and master and work on supporting the newer version.

@lathiat
Copy link
Author

lathiat commented Oct 24, 2023

Looks like master is already pinned to ruamel.yaml < 0.18 "so that dependencies can be consumed from versions from the Ubuntu distribution wherever possible.". So, for now, we just need to make the same change in the 2.8 branch.

lathiat added a commit to lathiat/charm-tools that referenced this issue Oct 24, 2023
ruamel.yaml 0.18 hard deprecated the old PyYAML functions removing
yaml.safe_load among many others. This causes charm-build to exit
sometimes without a visible error.

Fixes: juju#668
Reference: https://pypi.org/project/ruamel.yaml/0.18.0/
@lathiat
Copy link
Author

lathiat commented Oct 24, 2023

For some reason I can't figure out, the warnings.warn() that the ruamel library calls before running sys.exit(1) is not logged by charm-build. So this error is entirely not obvious, I could only figure it out by adding "python -m trace --trace" to the charm-build invocation. That will make it hard for impacted charms to debug this issue (which is a lot of openstack stable charms). They all pin charm-tools to specific 2.8.x versions so even once we commit a fix people are likely to be confused by the lack of error in th elog.

logging.captureWarnings(True) is run before the config code runs and if I add a call to warnings.warn from inside build/config.py right before the yaml call, it's logged, but once it calls into the ruamel library it is not. I must be missing something to do with scoping or when/the order the code is loaded here.

However I think sys.exit(1) is not really ideal behaviour for a library, so I filed an upstream bug to ask them to consider something that may be more obvious if warnings are disabled such as raising an exception or simply removing the function definition (which would then raise an exception):
https://sourceforge.net/p/ruamel-yaml/tickets/486/

@lathiat
Copy link
Author

lathiat commented Oct 27, 2023

Fixed by #669 and the subsequent release of 2.8.8

@lathiat lathiat closed this as completed Oct 27, 2023
openstack-mirroring pushed a commit to openstack/charm-octavia that referenced this issue Nov 29, 2023
Switch to using the latest charm-tools <3.0.0 to fix two build errors:
- An error related to 'pytz' fixed in charm-tools 2.8.6:
  juju/charm-tools#654
- An error related to ruamel.yaml fixed in charm-tools 2.8.8:
  here: juju/charm-tools#668

Additionally merge bindep.txt to install libpq-dev required for
psycopg2-binary as wheels no longer exist for py36.

Change-Id: Idc16b84dc3dcdf001c73c7d2fdd57b1d08ebfb23
openstack-mirroring pushed a commit to openstack/charm-octavia that referenced this issue Mar 6, 2024
Switch to using the latest charm-tools <3.0.0 to fix three build errors:
- An error related to 'pytz' fixed in charm-tools 2.8.6:
  juju/charm-tools#654
- An error related to ruamel.yaml fixed in charm-tools 2.8.8:
  here: juju/charm-tools#668
- An error related to macaroonbakery fixed in charm-tools 2.8.9:
  juju/charm-tools#671

Additionally merge bindep.txt to install libpq-dev required for
psycopg2-binary as wheels no longer exist for py36.

Additional fix for ussuri only:
- Switch bionic test bundles from vault 1.7/edge to 1.6/edge as the 1.7
  channel no longer supports bionic.

Change-Id: Idc16b84dc3dcdf001c73c7d2fdd57b1d08ebfb23
openstack-mirroring pushed a commit to openstack/charm-mysql-router that referenced this issue Apr 3, 2024
unpin charm-tools version as later version has fix for below discussion

https: //github.com/juju/charm-tools/issues/668
Change-Id: Ibfd2718d94f2270a32f97d9c7d19cec8ee988b52
openstack-mirroring pushed a commit to openstack/openstack that referenced this issue Apr 3, 2024
* Update charm-mysql-router from branch 'master'
  to 13b3d7a9bcdc3b51f6e28a3d4d1a81d5cfb572ce
  - Fixing charm-tools version
    
    unpin charm-tools version as later version has fix for below discussion
    
    https: //github.com/juju/charm-tools/issues/668
    Change-Id: Ibfd2718d94f2270a32f97d9c7d19cec8ee988b52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant