Skip to content

[Internal] DTS: Removes dead code and refactors to manual JSON deserialization#5896

Merged
Meghana-Palaparthi merged 4 commits into
mainfrom
users/Meghana-Palaparthi/dtx_remove_unused_properties
May 29, 2026
Merged

[Internal] DTS: Removes dead code and refactors to manual JSON deserialization#5896
Meghana-Palaparthi merged 4 commits into
mainfrom
users/Meghana-Palaparthi/dtx_remove_unused_properties

Conversation

@Meghana-Palaparthi
Copy link
Copy Markdown
Contributor

Pull Request Template

Description

This pull request refactors the distributed transaction response and operation result handling in the Cosmos DB SDK. The main focus is on removing dependencies on System.Text.Json.Serialization attributes and reflection-based deserialization, instead implementing explicit JSON parsing logic. Additionally, error message and tracing fields are removed from the public API surface and internal data flow, simplifying the object model.

Serialization and Deserialization Refactoring

  • Removed all System.Text.Json.Serialization attributes (such as [JsonInclude], [JsonPropertyName], [JsonIgnore], and [JsonConstructor]) from DistributedTransactionOperationResult and replaced reflection-based deserialization with a manual, case-insensitive property lookup and assignment in the new FromJson method. (DistributedTransactionOperationResult.cs)
  • Added a new helper method TryGetProperty for case-insensitive property lookup when parsing JSON elements. (DistributedTransactionOperationResult.cs)
  • Updated the deserialization logic in DistributedTransactionResponse to use the new explicit parsing methods instead of relying on System.Text.Json attributes. (DistributedTransactionResponse.cs) [1] [2]

Error Message and Tracing Cleanup

  • Removed the ErrorMessage property and associated logic from DistributedTransactionResponse and related constructors, as well as the corresponding test assertions. (DistributedTransactionResponse.cs, DistributedTransactionResponseTests.cs) [1] [2] [3] [4] [5]
  • Removed the Trace and ActivityId fields from both DistributedTransactionResponse and DistributedTransactionOperationResult, and eliminated their propagation through constructors and methods. (DistributedTransactionResponse.cs, DistributedTransactionOperationResult.cs) [1] [2] [3] [4] [5]

Public API Simplification

  • Changed several properties in DistributedTransactionOperationResult (such as SessionToken, PartitionKeyRangeId, and SubStatusCode) from public to internal, further restricting their visibility and clarifying the public API. (DistributedTransactionOperationResult.cs)

Test Adjustments

  • Updated tests to match the new deserialization logic and removed checks for properties that no longer exist (such as SubStatusCodeValue). (DistributedTransactionResponseTests.cs) [1] [2]

These changes collectively improve maintainability, reduce reliance on reflection and serialization attributes, and clarify the SDK's public and internal APIs.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [] This change requires a documentation update

Closing issues

To automatically close an issue: closes #IssueNumber

Changelog

  • I have added a changelog entry under ### Unreleased in changelog.md
    for the user-facing impact of this change.
  • No changelog entry is required because this PR is one of:
    documentation-only, test-only, CI / build-only, or a pure internal refactor
    with no observable customer impact.

If the second box is checked, briefly justify here:

Feature isn't public yet.

…alization

- Remove unused copy constructor, ErrorMessage property, ITrace plumbing, and per-operation ActivityId/Trace dead stores from response classes
- Replace System.Text.Json attribute-based deserialization with manual case-insensitive JsonElement.TryGetProperty parsing
- Make SessionToken, PartitionKeyRangeId, and SubStatusCode internal (were public only to satisfy STJ reflection requirements)
- Remove public SubStatusCodeValue bridge property (no longer needed)
- Add null-safety guards for string fields in JSON deserialization
kushagraThapar
kushagraThapar previously approved these changes May 22, 2026
Copy link
Copy Markdown
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanup, @Meghana-Palaparthi — the manual JSON deserializer is the right shape and aligns nicely with what TransactionalBatchOperationResult, Java's BatchResponseParser, and Python's batch-response paths already do (no STJ attributes, direct property walks). The public→internal demotions for SessionToken / PartitionKeyRangeId / SubStatusCode / ActivityId / Trace also bring DTS in line with TransactionalBatchOperationResult.cs:94,99,104, which I think is the right consolidation.

Approving since this is [Internal] and there are no shipped customers yet. I've left a few inline observations on correctness fidelity vs the old JsonSerializer.Deserialize<T> path that would be worth picking up in a follow-up PR — especially the InvalidOperationException leak from EnumerateObject() and the silent-default behavior on numeric type mismatches. These are subtle behavior changes customers won't see today, but the DTS team is likely to hit them during internal testing.

None of the inline items block this PR — they're all opportunities for a small fast-follow.

kushagraThapar
kushagraThapar previously approved these changes May 26, 2026
Copy link
Copy Markdown
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @Meghana-Palaparthi

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 27, 2026

📝 Changelog reminder (non-blocking)

This PR touches shipped source but does not appear to update the
corresponding changelog.md.

Touched (and missing entry for):

  • Microsoft.Azure.Cosmos/src/** ⇒ expected an entry in changelog.md (### Unreleased)

How to decide

Use the rubric in .github/copilot-instructions.md ("Changelog
classifier") or in CONTRIBUTING.md ("Changelog entry"). Quick
version:

  • Customer-observable change (behavior, perf, memory, API) ⇒ add an entry, even if the PR is [Internal].
  • Test-only / CI-only / doc-only / pure-internal-refactor with zero customer-observable effect ⇒ no entry, add the no-changelog-needed label to silence this check.
  • Unsure? Default to adding a one-line entry under #### Other Changes. Reviewer will adjust.

This check is non-blocking — merge is not gated on it. The
reviewer is responsible for the final classification.

…ibutes, consolidate tests

- All property name lookups (including resourceBody) now use case-insensitive
  TryGetProperty; removed unused TryGetPropertyOrdinal method
- Top-level response properties (isRetriable, diagnosticString,
  operationResponses) switched from ordinal to case-insensitive lookup
- Removed [JsonIgnore], [JsonConstructor] attributes and
  System.Text.Json.Serialization using (dead code since manual FromJson parsing)
- Changed parameterless constructor from public back to internal
- Consolidated repetitive tests into DataTestMethods (NumericTypeMismatch +
  NonObjectElement, Indexer bounds, IdempotencyToken fallback)
- Removed redundant tests (Dispose_ReleasesResultResourceStreams,
  FollowedByDirectStreamRead)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Meghana-Palaparthi Meghana-Palaparthi enabled auto-merge (squash) May 28, 2026 22:55
Copy link
Copy Markdown
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @Meghana-Palaparthi

@Meghana-Palaparthi Meghana-Palaparthi merged commit 43664a8 into main May 29, 2026
33 checks passed
@Meghana-Palaparthi Meghana-Palaparthi deleted the users/Meghana-Palaparthi/dtx_remove_unused_properties branch May 29, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants