feat(users): preserve handles and role assignments via v1#635
Merged
Conversation
michael-richey
marked this pull request as ready for review
July 17, 2026 16:22
michael-richey
force-pushed
the
users-handle-mapping-key
branch
3 times, most recently
from
July 17, 2026 18:20
8523e02 to
f54b846
Compare
Users were identified and linked by email, but the destination enforces user uniqueness on the handle (email is not unique). Two source users that share an email but have distinct handles collapsed onto one derived handle — one user was mislabeled and the other could not be created. - Identify/link users by their exact-case handle: switch resource_mapping_key to attributes.handle. Keep handle out of the read-only v2 create/update payload (pop before POST/PATCH) and out of update diffs (exclude_regex_paths), while retaining it for mapping and v1 creation. - Add an opt-in --use-v1-user-api flag (default off; env DD_USE_V1_USER_API). When set, create users via POST /api/v1/user, which accepts an explicit handle, so every user keeps its own handle and no create collides. The v1 response is the legacy shape, so re-resolve the v2 UUID by exact-case handle (small sleep-free re-query loop for read-after-write visibility); failures re-raise so the apply loop continues (DR-safe). With the flag off, creation is unchanged (v2). - Document the flag in the README; add pytest-cov to test extras. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
michael-richey
force-pushed
the
users-handle-mapping-key
branch
from
July 17, 2026 18:49
f54b846 to
803dcf2
Compare
michael-richey
marked this pull request as draft
July 17, 2026 19:16
michael-richey
marked this pull request as ready for review
July 17, 2026 20:02
There was a problem hiding this comment.
Pull request overview
Adds an opt-in v1 user-creation path to preserve exact-case user handles (avoiding shared-email collisions), switches user mapping to be handle-based, and makes role reconciliation retryable/observable via structured partial failures.
Changes:
- Map existing/users-by-handle (
attributes.handle) and exclude handle from v2 create/update payloads and diffs. - Add
--use-v1-user-api/DD_USE_V1_USER_APIto create users viaPOST /api/v1/user, then reconcile the v2 UUID by exact-case handle. - Reconcile only missing role assignments, continue after per-role failures, persist partial state, and raise a structured
UserRoleAssignmentError.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
datadog_sync/model/users.py |
Handle-based mapping, optional v1 create flow, role reconciliation + partial failure error type, v2 payload filtering/diff exclusion. |
datadog_sync/utils/configuration.py |
Adds use_v1_user_api to configuration and wiring from CLI kwargs. |
datadog_sync/commands/shared/options.py |
Introduces --use-v1-user-api CLI option + env var support. |
datadog_sync/constants.py |
Adds DD_USE_V1_USER_API constant. |
README.md |
Documents the v1 user creation flag and the shared-email handle-collision rationale. |
tests/unit/test_users.py |
New unit tests covering handle mapping, v1/v2 create paths, UUID reconciliation, role assignment behavior, and flag wiring. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
heyronhay
approved these changes
Jul 20, 2026
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.
What
Preserve distinct user handles during sync by mapping users by exact-case handle and optionally creating them through the v1 user API. Reconcile role assignments after creation and on later retries without reporting partial results as full success.
Why
Email is not necessarily unique, but the v2 create endpoint derives the destination handle from email. Distinct source users that share an email can therefore collide on one destination handle. The v1 endpoint accepts an explicit handle.
Role assignment is a separate API operation. A user can be created or updated successfully while one or more role assignments fail, so those partial outcomes must remain retryable and observable.
Changes
attributes.handleinstead of email, preserving exact case.--use-v1-user-apiflag andDD_USE_V1_USER_APIenvironment variable; both default off.POST /api/v1/user, then resolve the v2 UUID by exact-case handle for destination state and downstream references.Compatibility
With the flag disabled, user creation continues to use v2. Existing destination state produced by earlier handle collisions is not rewritten automatically; affected state must be cleaned before enabling the v1 path.
Tests