refactor(python): update validation logic to support mixed catalogs - #2398
refactor(python): update validation logic to support mixed catalogs#2398nan-yu wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request consolidates and refactors the validation logic across the repository, migrating core validation components to a2ui_core and removing the deprecated validator.py. While the restructuring is beneficial, there are critical issues that must be resolved before merging: unresolved git merge conflict markers exist in base.py within both the imports and the operation extraction logic. Additionally, there is redundant validation in base.py due to recursive calls inside a loop, and a potential TypeError crash in composition_validator.py if comp is not verified as a dictionary.
I am having trouble creating individual review comments. Click here to see my feedback.
python/a2ui_core/src/a2ui/core/processing/adapters/base.py (17-23)
Unresolved git merge conflict markers found in the imports section. Please resolve the conflict and clean up the markers.
from typing import Any, Dict, List, Optional, Set, Union
from pydantic import ValidationErrorpython/a2ui_core/src/a2ui/core/processing/adapters/base.py (227-256)
Unresolved git merge conflict markers found in the operation extraction logic. Please resolve the conflict by choosing the correct implementation branch and consistently using raw_payload (which is already converted to a dictionary).
ver_str = (
self.version.value
if hasattr(self.version, "value")
else str(self.version)
)
if ver_str != "v0.8":
if "version" not in raw_payload:
raise A2uiValidationError(
f"Invalid {self.version} message: messages.0.version: 'version'"
" is a required property"
)
if raw_payload["version"] != ver_str:
raise A2uiValidationError(
f"Invalid {self.version} message: messages.0.version: Input"
f" should be '{ver_str}'"
)
prepared_msg = self.prepare_payload_for_validation(raw_payload)
try:
self.schema.model_validate({"messages": [prepared_msg]})
except ValidationError as e:
details = self._format_validation_errors(e, [raw_payload])
summary = "; ".join(f"{d.path}: {d.message}" for d in details)
raise A2uiValidationError(f"Invalid {self.version} message: {summary}")
return self._extract_operations_for_action(action, raw_payload)python/a2ui_core/src/a2ui/core/processing/adapters/base.py (206-208)
The loop calls self._extract_single_action(item) to validate each item in the list. However, when self.extract_operations(item) is called recursively, it executes _extract_single_action again on the same items. This causes redundant validation and duplicate execution of _get_surface_id. Consider refactoring to perform this validation only once per payload.
References
- Avoid calling recursive payload traversal functions inside loops over messages to prevent redundant traversals and O(N^2) complexity. Run the traversal once per payload instead.
python/a2ui_core/src/a2ui/core/validation/composition_validator.py (42-44)
Ensure comp is a dictionary before calling .get() or iterating over its items in validate_composition_constraints to prevent potential TypeError or AttributeError crashes if invalid payloads are passed.
for comp in new_components:
if not isinstance(comp, dict):
continue
c_id = comp.get("id")
c_type = comp.get("component")
References
- When validation checks or function arguments can be represented as either a dictionary (named) or a list (positional), always verify the type (e.g., using
isinstance(args, dict)) before performing key-based lookups or assignments to preventTypeErrorcrashes.
e181cd2 to
53554bf
Compare
Consolidates schema validation into CatalogSchemaValidator and surface graph validation into SurfaceComponentsModel. Removes monolithic A2uiValidator. TAG=agy CONV=707c9b6b-b2da-4940-ba6e-67f0b4f1d563
TAG=agy CONV=707c9b6b-b2da-4940-ba6e-67f0b4f1d563
…ter error formatting
…, and generic model types - Simplify MessageProcessor.process_messages to resolve version adapters directly via VersionAdapterFactory.resolve_from_payload - Consolidate component validation into PayloadValidator and SurfaceComponentsModel.validate_components_update - Update SurfaceModel, SurfaceGroupModel, DataContext, and NodeGraph to bind TComponent and TFunction generics with PEP 696 defaults - Add tests and update conformance suites
4ebea53 to
d6df665
Compare
…function schema unwrapping
…able composition/theme conformance tests
… payload validation
…expected schema version
Stacked on top of #2379.
TAG=agy
CONV=707c9b6b-b2da-4940-ba6e-67f0b4f1d563