Skip to content

Commit bf00604

Browse files
authored
test: handle API-computed filter fields in validation (#937)
1 parent 96eeaeb commit bf00604

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

tests/model_registry/model_catalog/db_constants.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,26 @@
55
# filterable properties for CatalogModel. Based on GetFilterableProperties in
66
# kubeflow/model-registry catalog/internal/db/service/catalog_model.go (PR #1875)
77
#
8-
# Property naming:
9-
# - Context properties: base name only (special case: 'validated_on.array_value' for arrays)
10-
# - Artifact properties: 'artifacts.{name}.{type}' where type is string_value/array_value/double_value/int_value
8+
# Query structure:
9+
# 1. First SELECT: Context properties (model-level metadata)
10+
# - Core properties: Return base name only (e.g., license, provider, tasks)
11+
# - Custom properties with known types: Add type suffix (e.g., model_type.string_value, validated_on.array_value)
12+
# 2. UNION ALL
13+
# 3. Second SELECT: Artifact properties (model artifact metadata)
14+
# - Format: 'artifacts.{property_name}.{value_type}'
15+
# - Value types: string_value, array_value, double_value, int_value
1116
#
1217
# Return format:
13-
# - String/array properties: text array of values
18+
# - String/array properties: PostgreSQL text array of distinct values
1419
# - Numeric properties: 2-element text array [min, max] converted from double/int columns
1520
FILTER_OPTIONS_DB_QUERY = """
1621
SELECT
1722
CASE
18-
WHEN name = 'validated_on' AND array_value IS NOT NULL THEN name || '.array_value'
23+
-- Custom properties with array_value get .array_value suffix
24+
WHEN name IN ('validated_on') AND array_value IS NOT NULL THEN name || '.array_value'
25+
-- Custom properties with string_value get .string_value suffix
26+
WHEN name IN ('model_type', 'size', 'tensor_type', 'variant_group_id') THEN name || '.string_value'
27+
-- Core properties keep base name only
1928
ELSE name
2029
END AS name,
2130
COALESCE(string_value, array_value, '{}'::text[]) AS array_agg
@@ -176,6 +185,11 @@
176185
"artifacts.model_id.string_value", # artifact property with full name
177186
}
178187

188+
# Fields that are dynamically computed and added by the API but do not exist in the database
189+
API_COMPUTED_FILTER_FIELDS = {
190+
"status", # Computed from CatalogSource.status field
191+
}
192+
179193
# SQL query for accuracy sorting database validation
180194
# Returns an ordered list of model names (context names) that have accuracy metrics.
181195
# Models are ordered by their overall_average (accuracy) value from artifact properties.

tests/model_registry/model_catalog/test_filter_options_endpoint.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
parse_psql_output,
99
compare_filter_options_with_database,
1010
)
11-
from tests.model_registry.model_catalog.db_constants import FILTER_OPTIONS_DB_QUERY, API_EXCLUDED_FILTER_FIELDS
11+
from tests.model_registry.model_catalog.db_constants import (
12+
FILTER_OPTIONS_DB_QUERY,
13+
API_EXCLUDED_FILTER_FIELDS,
14+
API_COMPUTED_FILTER_FIELDS,
15+
)
1216
from tests.model_registry.utils import get_rest_headers, execute_get_command
1317
from utilities.user_utils import UserTestSession
1418

@@ -132,8 +136,15 @@ def test_comprehensive_coverage_against_database(
132136
db_properties = parsed_result.get("properties", {})
133137
LOGGER.info(f"Raw database query returned {len(db_properties)} properties: {list(db_properties.keys())}")
134138

139+
# Remove API-computed fields from API response before comparison
140+
filtered_api_filters = {
141+
key: value for key, value in api_filters.items() if key not in API_COMPUTED_FILTER_FIELDS
142+
}
143+
135144
is_valid, comparison_errors = compare_filter_options_with_database(
136-
api_filters=api_filters, db_properties=db_properties, excluded_fields=API_EXCLUDED_FILTER_FIELDS
145+
api_filters=filtered_api_filters,
146+
db_properties=db_properties,
147+
excluded_fields=API_EXCLUDED_FILTER_FIELDS,
137148
)
138149

139150
if not is_valid:

0 commit comments

Comments
 (0)