Skip to content

Commit cc05c02

Browse files
author
Bob Strahan
committed
improve stickler debug logging
1 parent 3ceea28 commit cc05c02

File tree

3 files changed

+84
-784
lines changed

3 files changed

+84
-784
lines changed

lib/idp_common_pkg/idp_common/evaluation/service.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ def _get_stickler_model(
394394
f" Expected data keys for {document_class}: {list(expected_data.keys())}"
395395
)
396396

397+
# DEBUG: Log full JSON Schema for detailed troubleshooting
398+
if logger.isEnabledFor(logging.DEBUG):
399+
import json
400+
401+
logger.debug(
402+
f"Full JSON Schema for {document_class}: "
403+
f"{json.dumps(schema, default=str)}"
404+
)
405+
397406
try:
398407
# Use JsonSchemaFieldConverter to handle the full JSON Schema natively
399408
from stickler.structured_object_evaluator.models.json_schema_field_converter import (
@@ -411,6 +420,34 @@ def _get_stickler_model(
411420
f"Successfully converted schema for {document_class} with {len(field_definitions)} fields"
412421
)
413422

423+
# DEBUG: Log converted field definitions with detailed type information
424+
if logger.isEnabledFor(logging.DEBUG):
425+
properties = schema.get("properties", {})
426+
field_details = []
427+
for name, field_info in field_definitions.items():
428+
prop_schema = properties.get(name, {})
429+
comparator = prop_schema.get(
430+
"x-aws-stickler-comparator", "inferred"
431+
)
432+
threshold = prop_schema.get("x-aws-stickler-threshold")
433+
weight = prop_schema.get("x-aws-stickler-weight")
434+
435+
detail = f" - {name}: {field_info[0].__name__ if hasattr(field_info[0], '__name__') else field_info[0]}"
436+
if comparator != "inferred":
437+
detail += f" (comparator={comparator}"
438+
if threshold is not None:
439+
detail += f", threshold={threshold}"
440+
if weight is not None:
441+
detail += f", weight={weight}"
442+
detail += ")"
443+
444+
field_details.append(detail)
445+
446+
logger.debug(
447+
f"Converted field definitions for {document_class}:\n"
448+
+ "\n".join(field_details)
449+
)
450+
414451
except Exception as e:
415452
# Enhanced error handling with user guidance
416453
import json
@@ -480,6 +517,52 @@ def _get_stickler_model(
480517
self._model_cache[cache_key] = model_class
481518
logger.debug(f"Cached Stickler model: {model_class.__name__}")
482519

520+
# DEBUG: Log Pydantic model structure for verification
521+
if logger.isEnabledFor(logging.DEBUG):
522+
model_fields_info = (
523+
model_class.model_fields if hasattr(model_class, "model_fields") else {}
524+
)
525+
field_types = [
526+
f" {k}: {v.annotation}" for k, v in model_fields_info.items()
527+
]
528+
logger.debug(
529+
f"Created Pydantic model structure for {document_class}:\n"
530+
f" Model: {model_class.__name__}\n"
531+
f" Base classes: {[base.__name__ for base in model_class.__bases__]}\n"
532+
f" Field count: {len(model_fields_info)}\n"
533+
f" Field types:\n" + "\n".join(field_types)
534+
if field_types
535+
else " (no fields)"
536+
)
537+
538+
# DEBUG: Test instantiation with expected data (if available)
539+
if expected_data and logger.isEnabledFor(logging.DEBUG):
540+
try:
541+
# Clean and coerce data before test instantiation
542+
cleaned_data = self._remove_none_values(expected_data)
543+
coerced_data = self._coerce_data_to_schema(cleaned_data, model_class)
544+
test_instance = model_class(**coerced_data)
545+
546+
# Serialize the instance to show what Stickler will work with
547+
if hasattr(test_instance, "model_dump"):
548+
serialized = test_instance.model_dump()
549+
elif hasattr(test_instance, "dict"):
550+
serialized = test_instance.dict()
551+
else:
552+
serialized = dict(test_instance)
553+
554+
import json
555+
556+
logger.debug(
557+
f"Test instantiation successful for {document_class}: "
558+
f"{json.dumps(serialized, default=str)}"
559+
)
560+
except Exception as e:
561+
logger.debug(
562+
f"Test instantiation failed for {document_class} "
563+
f"(this is informational only): {str(e)}"
564+
)
565+
483566
return model_class
484567

485568
def _prepare_stickler_data(self, uri: str) -> Tuple[Dict[str, Any], Dict[str, Any]]:

0 commit comments

Comments
 (0)