GOV-667 | feat: Prevent duplicate AuthPolicy creation on timeout retries#878
Merged
Aryamanz29 merged 5 commits intomainfrom Mar 25, 2026
Merged
GOV-667 | feat: Prevent duplicate AuthPolicy creation on timeout retries#878Aryamanz29 merged 5 commits intomainfrom
Aryamanz29 merged 5 commits intomainfrom
Conversation
Aryamanz29
approved these changes
Mar 24, 2026
Member
Aryamanz29
left a comment
There was a problem hiding this comment.
looks good; one minor doubt below:
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Aryamanz29
approved these changes
Mar 25, 2026
Member
Aryamanz29
left a comment
There was a problem hiding this comment.
LGTM - thanks! @ankitpatnaik-atlan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Overview
Prevents duplicate metadata policy creation when API requests timeout and are retried. The solution adds intelligent duplicate detection only during API attempts, preserving existing functionality while preventing duplicates caused by timeout-retry scenarios.
Problem
When creating metadata policies in tenants with 700+ existing policies:
Solution
Smart Request Handling with Duplicate Detection
The fix modifies the transport retry logic to check for existing policies before every API attempt (first attempt +
retries):
NORMAL FLOW (no existing policy):
✅ Check for duplicate → Not found
✅ Create policy → Success
TIMEOUT + RETRY FLOW:
⏱️ Check for duplicate → Not found
⏱️ Create policy → Timeout (but succeeds server-side)
🔍 Before retry: Check for duplicate → Found!
✅ Return existing policy (prevent duplicate)
AUTOMATION RE-RUN:
🔍 Check for duplicate → Found!
✅ Return existing policy (idempotent)
Changes Made
1. New Module:
pyatlan/client/common/transport.pyShared utilities for duplicate AuthPolicy detection:
parse_auth_policy_entity()- Extracts policy metadata from bulk POST requestsbuild_policy_search_request()- Constructs IndexSearch query for existing policiesget_persona_qualified_name()/get_persona_qualified_name_async()- Resolves persona QN by GUIDfind_existing_policy()/find_existing_policy_async()- Searches for existing policy by name + personacheck_for_duplicate_policy()/check_for_duplicate_policy_async()- Main duplicate check orchestrationcreate_mock_response()- Creates HTTP response with existing policy data2. Enhanced Transport:
pyatlan/client/transport.pyModified both sync and async transports:
clientparameter to store AtlanClient reference_retry_operation()/_retry_operation_async()to check for duplicates before every attempt3. New Error Codes:
pyatlan/errors.pyAdded error codes for duplicate prevention:
UNABLE_TO_SEARCH_EXISTING_POLICY(ATLAN-PYTHON-500-007)UNABLE_TO_RESOLVE_PERSONA_QUALIFIED_NAME(ATLAN-PYTHON-500-008)4. Comprehensive Test Coverage
Unit tests (
tests/unit/test_transport.py):Integration tests (
tests/integration/test_transport.py,tests/integration/aio/test_transport.py):Key Features
✅ Non-breaking: No changes to existing API or customer code required
✅ Targeted: Only affects retry/attempt scenarios (the actual problem)
✅ Safe: Falls back to normal request if duplicate check fails
✅ Logged: Clear warning messages when duplicate detected
✅ Idempotent: Allows safe automation re-runs
✅ Transparent: Users get the policy they want (existing or new)
Graceful Degradation
If the duplicate check search fails (index down, network issue, etc.):
None(no duplicate found)Performance Impact
Backwards Compatibility
✅ Fully backwards compatible:
Testing
All tests passing:
Related
Note
Medium Risk
Changes core HTTP transport retry behavior to perform pre-flight duplicate detection for
AuthPolicybulk creates, which can alter request flow and add extra IndexSearch calls per attempt. While scoped and fail-open, incorrect matching or search latency could impact policy save behavior in edge cases.Overview
Prevents duplicate
AuthPolicycreation by adding a transport-layer duplicate check for bulk policy creates (temp GUIDs) and short-circuiting requests by returning a mock bulk response when an existing policy is found.Improves the duplicate search to resolve persona GUID to
qualifiedNameand then search policies using aqualifiedNameprefix plus additional filters (ACTIVE,policyCategory=persona), and updates retry logic to run this check before every attempt (first + retries) while treating search failures as non-blocking.Adds
ErrorCode.UNABLE_TO_RESOLVE_PERSONA_QUALIFIED_NAMEand updates unit/integration tests to cover first-attempt detection, retry-time detection, update-vs-create parsing, and graceful degradation on search errors.Written by Cursor Bugbot for commit 04a951a. This will update automatically on new commits. Configure here.