recursion
pyvider.cty.validation.recursion
¶
Advanced recursion detection for CTY validation.
This module provides sophisticated recursion detection that can distinguish between: 1. Genuine circular references that would cause infinite loops 2. Normal nested data structures with repetitive patterns 3. Deep but finite nesting that should be allowed
The implementation is designed for production IaC requirements where: - Complex configurations with deep nesting must be supported - Genuine circular references must be prevented - Performance must be predictable and measurable - Debugging and monitoring capabilities are essential
Classes¶
RecursionContext
dataclass
¶
RecursionContext(
validation_graph: dict[int, ValidationNode] = dict(),
validation_path: list[str] = list(),
max_depth_reached: int = 0,
total_validations: int = 0,
validation_start_time: float = time.time(),
max_depth_allowed: int = MAX_VALIDATION_DEPTH,
max_object_revisits: int = MAX_OBJECT_REVISITS,
max_validation_time_ms: int = MAX_VALIDATION_TIME_MS,
validation_stopped: bool = False,
)
RecursionDetector
¶
Advanced recursion detector for CTY validation.
This detector uses sophisticated algorithms to distinguish between: - Circular references (object A -> object B -> object A) - Deep but finite nesting (legitimate complex configurations) - Performance pathological cases (excessive validation time)
Source code in pyvider/cty/validation/recursion.py
Functions¶
enter_validation_scope
¶
exit_validation_scope
¶
get_current_path
¶
get_performance_metrics
¶
Get performance metrics for monitoring and debugging.
Source code in pyvider/cty/validation/recursion.py
should_continue_validation
¶
Determine if validation should continue for the given value.
Returns:
| Type | Description |
|---|---|
tuple[bool, str | None]
|
(should_continue, reason_if_stopped) |
Production requirements: - Must handle legitimate deep nesting (1000+ levels) - Must detect genuine circular references quickly - Must provide detailed diagnostics for debugging - Must have predictable performance characteristics
Source code in pyvider/cty/validation/recursion.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
ValidationNode
dataclass
¶
ValidationNode(
object_id: int,
object_type: str,
depth: int,
parent_path: str,
first_seen_at: float = time.time(),
)
Represents a node in the validation graph for cycle detection.
Functions¶
clear_recursion_context
¶
get_recursion_context
¶
Get or create thread-local recursion context.
Source code in pyvider/cty/validation/recursion.py
with_recursion_detection
¶
Decorator for advanced recursion detection in validation functions.