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.17.0 has deprecated dump(), load() #765

Open
jwhitlock opened this issue Jan 4, 2022 · 3 comments
Open

ruamel.yaml 0.17.0 has deprecated dump(), load() #765

jwhitlock opened this issue Jan 4, 2022 · 3 comments

Comments

@jwhitlock
Copy link

Bug Report

drf_yasg is using functions that have been deprecated in ruamel.yaml 0.17.0, released 2021-03-26:

the old top level functions load, safe_load, round_trip_load, dump, safe_dump, round_trip_dump, scan, parse, compose, emit, serialize as well as their _all variants for multi-document streams, now issue a PendingDeprecationning (e.g. when run from pytest, but also Python is started with -Wd). Use the methods on YAML(), which have been extended.

I believe this affects only yaml_sane_dump and yaml_sane_load.

Is this a regression?

Not a drf-yasg one. ruamel.yaml 0.16.3, the first supported version and the last to support Python 2, does not have this deprecation warning. It also may not have the extended arguments to YAML()..

Minimal Reproduction

I discovered this while testing the endpoint with pytest in mozilla/fx-private-relay#1447.

Another way to reproduce it is with a short bit of code. Add this to a working Django / drf-yasg project as repo_bug.py:

from django.conf import settings

def test_round_trip():
    from drf_yasg.codecs import yaml_sane_dump, yaml_sane_load

    data = {"key": "value"}

    out = yaml_sane_dump(data, False)
    round_trip = yaml_sane_load(out)
    assert round_trip["key"] == "value"

if __name__ == "__main__":
    settings.configure()
    test_round_trip()

Run with python -Wd repo_bug.py. The -Wd is needed to display the PendingDeprecationWarnings.

Stack trace / Error message

../lib/python3.7/site-packages/drf_yasg/codecs.py:202: PendingDeprecationWarning: 
dump will be removed, use

  yaml=YAML(typ='unsafe', pure=True)
  yaml.dump(...)

instead
  return yaml.dump(data, Dumper=SaneYamlDumper, default_flow_style=False, encoding='utf-8' if binary else None)
../lib/python3.7/site-packages/ruamel/yaml/main.py:1380: PendingDeprecationWarning: 
dump_all will be removed, use

  yaml=YAML(typ='unsafe', pure=True)
  yaml.dump_all(...)

instead
  block_seq_indent=block_seq_indent,
../lib/python3.7/site-packages/drf_yasg/codecs.py:220: PendingDeprecationWarning: 
load will be removed, use

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

instead
  return yaml.load(stream, Loader=SaneYamlLoader)

Your Environment

Tested with Python 3.7.12 with these select dependencies:

Django==2.2.24
pytest==6.2.5
pytest-django==3.9.0
drf-yasg==1.20.0
ruamel.yaml==0.17.20
ruamel.yaml.clib==0.2.6
@creyD
Copy link

creyD commented Jul 19, 2022

@jwhitlock Is this issue closed, as the PRs were merged?

@jwhitlock
Copy link
Author

@jwhitlock Is this issue closed, as the PRs were merged?

The merged PRs are on our project, and mention this issue, mostly to say there is a warning that requires a drf-yasg fix, not one introduced by those PRs.

@jwhitlock
Copy link
Author

PR #806 is a fix for this drf-yasg project.

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

2 participants