feat(users): backfill destination email via a second PATCH when handle differs - #645
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a two-step v2 user creation flow to preserve the source handle when it differs from the source email, by creating the user with email=handle and then PATCHing the real email afterward.
Changes:
- Extend
Users.create_resource()to optionally do a follow-up PATCH to restore the real email whenhandle != email. - Persist partially-created user state when the email-restoring PATCH fails to avoid re-creates that would 409 on the already-taken handle.
- Add unit tests covering the two-call flow, the no-op case when
handle == email, and persistence on PATCH failure.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
datadog_sync/model/users.py |
Implements conditional “email backfill” logic via a second PATCH and persists state on PATCH failure. |
tests/unit/test_users.py |
Adds tests validating POST/PATCH behavior, no-backfill behavior, and failure-state persistence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…e differs v2 user creation derives the destination handle from the create-time email, so when a source user's handle isn't itself their email, create with the handle as the email (matching the destination handle to the source handle), then PATCH the real email in a second call. Falls back to a single create call when handle and email already match.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
michael-richey
force-pushed
the
michael.richey/v2-user-email-backfill
branch
from
July 27, 2026 19:51
8a9da73 to
085808a
Compare
riyazsh
approved these changes
Jul 27, 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.
Summary
v2 user creation (
POST /api/v2/users) derives the destinationhandlefrom the create-timeemailand does not accepthandledirectly. When a source user's handle isn't itself their email address, this leaves no way to make the destination handle match the source handle.This PR adds a two-call create path for that case:
POST /api/v2/userswith the source handle passed as the create-timeemail, so the destination derives a handle matching the source handle.PATCH /api/v2/users/{id}to set the real sourceemail.When the source handle already equals the source email, create is unchanged (a single POST).
Behavior
Test plan
tox -e py311)