Remove reduntant solution

This commit is contained in:
Alexsander Hamir 2026-01-28 16:01:47 -08:00
parent 12a9d351ac
commit dd05ae2748
2 changed files with 2 additions and 35 deletions

View file

@ -84,7 +84,6 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
presidio_score_thresholds: Optional[
Dict[Union[PiiEntityType, str], float]
] = None,
presidio_ad_hoc_recognizers_on_server: Optional[bool] = None,
**kwargs,
):
if logging_only is True:
@ -105,9 +104,6 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
presidio_score_thresholds or {}
)
self.presidio_language = presidio_language or "en"
self.presidio_ad_hoc_recognizers_on_server = (
presidio_ad_hoc_recognizers_on_server or False
)
# Shared HTTP session to prevent memory leaks (issue #14540)
self._http_session: Optional[aiohttp.ClientSession] = None
# Lock to prevent race conditions when creating session under concurrent load
@ -251,10 +247,7 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
##################################################################
###### Check if user has configured any params for this guardrail
################################################################
if (
self.ad_hoc_recognizers is not None
and self.presidio_ad_hoc_recognizers_on_server is False
):
if self.ad_hoc_recognizers is not None:
analyze_payload["ad_hoc_recognizers"] = self.ad_hoc_recognizers
if self.pii_entities_config:

View file

@ -70,30 +70,4 @@ async def test_bug_presidio_session_explosion_background_thread_causes_latency()
# FIX VERIFICATION: Should now be 1 session (reused) instead of 10.
assert session_creations == 1
await presidio._close_http_session()
@pytest.mark.asyncio
async def test_optimization_presidio_avoid_recognizer_reloads_on_server():
"""
OPTIMIZATION VERIFICATION:
Verify that ad_hoc_recognizers are OMITTED from the payload when
presidio_ad_hoc_recognizers_on_server is True.
Sending them on every request forces the Presidio server to reload its
entire registry, spiking CPU and latency.
"""
presidio = _OPTIONAL_PresidioPIIMasking(
mock_testing=True,
presidio_analyzer_api_base="http://mock-analyzer",
presidio_anonymizer_api_base="http://mock-anonymizer",
presidio_ad_hoc_recognizers_on_server=True
)
presidio.ad_hoc_recognizers = [{"name": "CustomRecognizer", "supported_entity": "CUSTOM"}]
payload = presidio._get_presidio_analyze_request_payload(
text="some text",
presidio_config=None,
request_data={}
)
# Optimization Check: payload should NOT contain the redundant recognizers
assert "ad_hoc_recognizers" not in payload
await presidio._close_http_session()