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

AttributeError: "safe_load()" has been removed #531

Open
fraricci opened this issue May 15, 2024 · 5 comments
Open

AttributeError: "safe_load()" has been removed #531

fraricci opened this issue May 15, 2024 · 5 comments
Labels
compatibility Concerning compatibility with different OS, Python versions, dependency versions, etc.

Comments

@fraricci
Copy link

fraricci commented May 15, 2024

Have you already seen this error?

I have a recent ruamel.yaml v.0.18.6 and got this error when trying to load the launchpad:
lpad = LaunchPad.auto_load() or lpad = LaunchPad.from_file()

The full error stack is the following:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[50], line 1
----> 1 LaunchPad.auto_load()

File ~/python-venvs/devel/lib64/python3.11/site-packages/fireworks/core/launchpad.py:313, in LaunchPad.auto_load(cls)
    310 @classmethod
    311 def auto_load(cls):
    312     if LAUNCHPAD_LOC:
--> 313         return LaunchPad.from_file(LAUNCHPAD_LOC)
    314     return LaunchPad()

File ~/python-venvs/devel/lib64/python3.11/site-packages/fireworks/utilities/fw_serializers.py:291, in FWSerializable.from_file(cls, filename, f_format)
    289     f_format = filename.split(".")[-1]
    290 with open(filename, "r", **ENCODING_PARAMS) as f:
--> 291     return cls.from_format(f.read(), f_format=f_format)

File ~/python-venvs/devel/lib64/python3.11/site-packages/fireworks/utilities/fw_serializers.py:256, in FWSerializable.from_format(cls, f_str, f_format)
    254     dct = json.loads(f_str)
    255 elif f_format == "yaml":
--> 256     dct = yaml.safe_load(f_str)
    257 else:
    258     raise ValueError(f"Unsupported format {f_format}")

File ~/python-venvs/devel/lib64/python3.11/site-packages/ruamel/yaml/main.py:1105, in safe_load(stream, version)
   1099 def safe_load(stream: StreamTextType, version: Optional[VersionType] = None) -> Any:
   1100     """
   1101     Parse the first YAML document in a stream
   1102     and produce the corresponding Python object.
   1103     Resolve only basic YAML tags.
   1104     """
-> 1105     error_deprecation('safe_load', 'load', arg="typ='safe', pure=True")

File ~/python-venvs/devel/lib64/python3.11/site-packages/ruamel/yaml/main.py:1039, in error_deprecation(fun, method, arg, comment)
   1037     raise AttributeError(s)
   1038 else:
-> 1039     raise AttributeError(s, name=None)

AttributeError: 
"safe_load()" has been removed, use

  yaml = YAML(typ='safe', pure=True)
  yaml.load(...)

instead of file "/home/fraricci/python-venvs/devel/lib64/python3.11/site-packages/fireworks/utilities/fw_serializers.py", line 256

            dct = yaml.safe_load(f_str)

Applying the suggested way of loading a file it works:

from ruamel.yaml import YAML
from pathlib import Path

yaml = YAML(typ='safe', pure=True)
yaml = yaml.load(Path("my_launchpad.yaml").read_text())
lpad = LaunchPad.from_dict(yaml)

If someone can confirm this, I can send a pull request with this fix.

Thanks

@ikondov
Copy link
Contributor

ikondov commented May 17, 2024

@fraricci Have you used the most recent release or the main branch? The issue has been already solved in the main branch since this PR #517 but is has not been released yet. So you do not have to provide a PR. For the time being, I would suggest that you pull and install from the main branch.

This issue is duplicate of #516.

@ikondov
Copy link
Contributor

ikondov commented May 17, 2024

Another workaround is to downgrade ruamel.yaml <0.18.0 if new installation/upgrade from fireworks main branch is not convenient. This is what I had done until PR #517 was merged.

@fraricci
Copy link
Author

fraricci commented May 17, 2024

Thank for you reply! I actually searched the issues, but not the pull requests, so I did not see that you had already mentioned and solved the issue. I have the fireworks version that comes with pip. Indeed I installed the last 0.17 version of ruamel.yaml to temporary solve the issue.

Given that relevance of your PR, I believe a new version of Fireworks should be released. @janosh @computron

Thanks!

@janosh
Copy link
Member

janosh commented May 17, 2024

i'm not a manager of fireworks pypi package and there's no release CI in place. so a new release has to be done by @computron

@janosh janosh added the compatibility Concerning compatibility with different OS, Python versions, dependency versions, etc. label May 17, 2024
@mattmcdermott
Copy link
Member

Both my coworker and I ran into this same issue and it took us a while to figure out (downgrading ruamel.yaml was the easy fix).

+1 for doing a new release! @computron

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Concerning compatibility with different OS, Python versions, dependency versions, etc.
Projects
None yet
Development

No branches or pull requests

4 participants