Silence per-request DeprecationWarning in the tag-filter remap shim
Reading the deprecated include_tags/exclude_tags fields by attribute fires pydantic's DeprecationWarning on every list/refine request even for callers using only the new names. The warning is aimed at API clients, not the server's own remap; read via model_dump instead.
This commit is contained in:
parent
43ccc2b6e0
commit
4eb312cd6c
|
|
@ -136,8 +136,12 @@ def _resolve_tag_filters(
|
|||
the legacy names keep their historical behaviour, including degenerate
|
||||
combinations like include_tags=a&exclude_tags=a.
|
||||
"""
|
||||
include_tags = normalize_tags(q.include_tags)
|
||||
exclude_tags = normalize_tags(q.exclude_tags)
|
||||
# model_dump instead of attribute access: the fields are deprecated, and
|
||||
# pydantic's per-access DeprecationWarning is aimed at API clients, not at
|
||||
# this remap shim reading them on every request.
|
||||
legacy = q.model_dump(include={"include_tags", "exclude_tags"})
|
||||
include_tags = normalize_tags(legacy["include_tags"])
|
||||
exclude_tags = normalize_tags(legacy["exclude_tags"])
|
||||
tags_all = normalize_tags(q.tags_all)
|
||||
tags_any = normalize_tags(q.tags_any)
|
||||
tags_none = normalize_tags(q.tags_none)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import time
|
||||
import uuid
|
||||
import warnings
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
from helpers import assert_hash_fields_consistent
|
||||
|
||||
from app.assets.api import routes as assets_routes
|
||||
from app.assets.api import schemas_in
|
||||
|
||||
|
||||
|
|
@ -717,6 +719,18 @@ def test_list_assets_tag_values_case_sensitive(http, api_base, asset_factory, ma
|
|||
assert names_for({"tags_all": f"unit-tests,{scope},{upper}", "tags_none": lower}) == {a["name"]}
|
||||
|
||||
|
||||
def test_resolve_tag_filters_no_deprecation_warning():
|
||||
"""The deprecated-field warning is for API clients; the server's own remap
|
||||
shim must not fire it on every request."""
|
||||
for q in (
|
||||
schemas_in.ListAssetsQuery(tags_all="a", tags_none="b"),
|
||||
schemas_in.TagsRefineQuery(tags_any="c"),
|
||||
):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error", DeprecationWarning)
|
||||
assets_routes._resolve_tag_filters(q)
|
||||
|
||||
|
||||
def test_tag_filter_alias_fields_marked_deprecated():
|
||||
for model in (schemas_in.ListAssetsQuery, schemas_in.TagsRefineQuery):
|
||||
props = model.model_json_schema()["properties"]
|
||||
|
|
|
|||
Loading…
Reference in New Issue