From 4eb312cd6c185f38a8b1a7207a8377b73fec3f07 Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Wed, 5 Aug 2026 13:32:50 -0700 Subject: [PATCH] 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. --- app/assets/api/routes.py | 8 ++++++-- tests-unit/assets_test/test_list_filter.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/assets/api/routes.py b/app/assets/api/routes.py index 2f25d8c90..63921cd1e 100644 --- a/app/assets/api/routes.py +++ b/app/assets/api/routes.py @@ -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) diff --git a/tests-unit/assets_test/test_list_filter.py b/tests-unit/assets_test/test_list_filter.py index fce269cd9..c5cb50b9c 100644 --- a/tests-unit/assets_test/test_list_filter.py +++ b/tests-unit/assets_test/test_list_filter.py @@ -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"]