Skip to content

Commit 0c612a0

Browse files
committed
making registry global
1 parent 122b6dc commit 0c612a0

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/eligibility_signposting_api/logging/logs_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def wrapper(event: LambdaEvent, context: LambdaContext) -> dict[str, Any] | None
3030

3131

3232
class EnrichedJsonFormatter(JsonFormatter):
33-
def add_fields(self, log_record: dict[str, Any], record: logging.LogRecord, message_dict: dict[str, Any]) -> None:
34-
log_record["request_id"] = request_id_context_var.get() or "-"
35-
super().add_fields(log_record, record, message_dict)
33+
def add_fields(self, log_data: dict[str, Any], record: logging.LogRecord, message_dict: dict[str, Any]) -> None:
34+
log_data["request_id"] = request_id_context_var.get() or "-"
35+
super().add_fields(log_data, record, message_dict)
3636

3737

3838
def init_logging(quieten: Sequence[str] = ("asyncio", "botocore", "boto3", "mangum", "urllib3")) -> None:

src/eligibility_signposting_api/services/processors/derived_values/registry.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,19 @@ def calculate(
149149
return handler.calculate(context)
150150

151151

152-
# Create a singleton instance for convenience
153-
_registry = DerivedValueRegistry()
152+
# Use a dict container for lazy singleton to avoid global statement
153+
_registry_container: dict[str, DerivedValueRegistry] = {}
154154

155155

156156
def get_registry() -> DerivedValueRegistry:
157157
"""Get the global derived value registry.
158158
159+
Uses lazy initialization to ensure default handlers are registered
160+
before the singleton is created.
161+
159162
Returns:
160163
The singleton DerivedValueRegistry instance
161164
"""
162-
return _registry
165+
if "instance" not in _registry_container:
166+
_registry_container["instance"] = DerivedValueRegistry()
167+
return _registry_container["instance"]

src/eligibility_signposting_api/services/processors/token_processor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from eligibility_signposting_api.model.person import Person
1010
from eligibility_signposting_api.services.processors.derived_values import (
1111
DerivedValueContext,
12-
DerivedValueRegistry,
12+
get_registry,
1313
)
1414
from eligibility_signposting_api.services.processors.token_parser import ParsedToken, TokenParser
1515

@@ -125,7 +125,7 @@ def get_derived_value(
125125
Raises:
126126
ValueError: If no handler is registered or attribute not found
127127
"""
128-
registry = DerivedValueRegistry()
128+
registry = get_registry()
129129

130130
function_name = parsed_token.function_name
131131
if not function_name:

0 commit comments

Comments
 (0)