Deprecation Warnings for acceptparse

Bug #1976220 reported by Hiromu Asahina
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
tacker
Fix Released
Undecided
Unassigned

Bug Description

The following warnings are emitted many times during unittest.

/opt/stack/tacker/.tox/py39/lib/python3.9/site-packages/webob/acceptparse.py:1047: DeprecationWarning: The behavior of AcceptValidHeader.best_match is currently being maintained for backward compatibility, but it will be deprecated in the future, as it does not conform to the RFC.
  warnings.warn(
/opt/stack/tacker/.tox/py39/lib/python3.9/site-packages/webob/acceptparse.py:4420: DeprecationWarning: The behavior of AcceptLanguageValidHeader.best_match is currently being maintained for backward compatibility, but it will be deprecated in the future as it does not conform to the RFC.
  warnings.warn(
/opt/stack/tacker/.tox/py39/lib/python3.9/site-packages/webob/acceptparse.py:1381: DeprecationWarning: The behavior of .best_match for the Accept classes is currently being maintained for backward compatibility, but the method will be deprecated in the future, as its behavior is not specified in (and currently does not conform to) RFC 7231.

This happens because webob emits a warning for this method for the reason that its algorithm does not conform to RFC 7231.
Need to use `acceptable_offers` for `accept` and `lookup` for `accept_language`, respectively (c.f., https://github.com/Cornices/cornice/pull/498/files#).

Revision history for this message
Hiromu Asahina (h-asahina) wrote :

As described in [1], best_match and lookup behave differently and are not replaceable directly. This difference might affect users, and thus leaving the current code is a better choice.

[1] https://docs.pylonsproject.org/projects/webob/en/stable/api/webob.html#webob.acceptparse.AcceptLanguageValidHeader.best_match

----
In [29]: from webob import Request

In [30]: req = Request.blank('/test?check=a&check=b&name=Bob')

In [31]: req.accept_language = 'en-gb;q=1, en;q=0.8'

In [32]: all_languages = ['en_US']

In [33]: req.accept_language.best_match(all_languages)
Out[33]: 'en_US'

In [35]: req.accept_language.lookup(all_languages, default='ja_JP')
Out[35]: 'ja_JP'

Changed in tacker:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to tacker (master)

Reviewed: https://review.opendev.org/c/openstack/tacker/+/843721
Committed: https://opendev.org/openstack/tacker/commit/e8dfc6b0372ba86020115395427fc010cfc89352
Submitter: "Zuul (22348)"
Branch: master

commit e8dfc6b0372ba86020115395427fc010cfc89352
Author: Hiromu Asahina <email address hidden>
Date: Sat May 28 13:15:24 2022 +0000

    Fix usage of deprecated .best_match()

    The webob emits a warning for best_match method for the reason that its
    algorithm does not conform to RFC 7231 [1]. This patch replace
    `best_match` with `acceptable_offers` as v2 API does [2].

    The following deprecation warnings are gone with the patch:

    - cceptparse.py:1047: DeprecationWarning: The behavior of
      AcceptValidHeader.best_match is currently being maintained for
      backward compatibility, but it will be deprecated in the future, as it
      does not conform to the RFC.

    [1]
    https://docs.pylonsproject.org/projects/webob/en/stable/api/webob.html#webob.acceptparse.AcceptValidHeader.best_match
    [2]
    https://github.com/openstack/tacker/blob/master/tacker/sol_refactored/api/wsgi.py#L37

    Change-Id: Ia68fa8acb7a27c17f9da7eea587112da4dedb892
    Closes-Bug: #1976220

Changed in tacker:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to tacker (stable/yoga)

Fix proposed to branch: stable/yoga
Review: https://review.opendev.org/c/openstack/tacker/+/845220

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to tacker (stable/yoga)

Reviewed: https://review.opendev.org/c/openstack/tacker/+/845220
Committed: https://opendev.org/openstack/tacker/commit/51ef6ca2cb922940c0b7e1c5e9b1dbe23c9b352c
Submitter: "Zuul (22348)"
Branch: stable/yoga

commit 51ef6ca2cb922940c0b7e1c5e9b1dbe23c9b352c
Author: Hiromu Asahina <email address hidden>
Date: Sat May 28 13:15:24 2022 +0000

    Fix usage of deprecated .best_match()

    The webob emits a warning for best_match method for the reason that its
    algorithm does not conform to RFC 7231 [1]. This patch replace
    `best_match` with `acceptable_offers` as v2 API does [2].

    The following deprecation warnings are gone with the patch:

    - cceptparse.py:1047: DeprecationWarning: The behavior of
      AcceptValidHeader.best_match is currently being maintained for
      backward compatibility, but it will be deprecated in the future, as it
      does not conform to the RFC.

    [1]
    https://docs.pylonsproject.org/projects/webob/en/stable/api/webob.html#webob.acceptparse.AcceptValidHeader.best_match
    [2]
    https://github.com/openstack/tacker/blob/master/tacker/sol_refactored/api/wsgi.py#L37

    Change-Id: Ia68fa8acb7a27c17f9da7eea587112da4dedb892
    Closes-Bug: #1976220
    (cherry picked from commit e8dfc6b0372ba86020115395427fc010cfc89352)

tags: added: in-stable-yoga
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/tacker 8.0.0.0rc1

This issue was fixed in the openstack/tacker 8.0.0.0rc1 release candidate.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/tacker 7.1.0

This issue was fixed in the openstack/tacker 7.1.0 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.