Skip to content

Conversation

@JoasE
Copy link
Contributor

@JoasE JoasE commented Sep 1, 2025

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

@JoasE
Copy link
Contributor Author

JoasE commented Sep 1, 2025

@dotnet-policy-service agree

@JoasE JoasE mentioned this pull request Sep 6, 2025
Comment on lines 652 to 658
wrapper._commandLogger.ExecutedTransactionalBatch(
response.Diagnostics.GetClientElapsedTime(),
response.Headers.RequestCharge,
response.Headers.ActivityId,
batch.Entries,
batch.CollectionId,
batch.PartitionKeyValue);
Copy link
Member

Choose a reason for hiding this comment

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

Since it's essentially a single database operation, just having one log entry per batch is appropriate. You can list the ids as an array [ "1", "2", "3" ] or a single ? if sensitive logging is not enabled

if (exception is not DbUpdateConcurrencyException
|| !Dependencies.Logger.OptimisticConcurrencyException(
entry.Context, errorEntries, (DbUpdateConcurrencyException)exception, null).IsSuppressed)
batch.Items.First().Entry.Context, batch.Items.Select(x => x.Entry).ToArray(), (DbUpdateConcurrencyException)exception, null).IsSuppressed)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure which entries to pass where here: the whole batch failed to write, but only a few items in the batch might have caused the problem. What if the user wants to reload the items and save them again? Is that possible? Or what if the user wants to retry the whole batch, but without the errored entries? Now I am passing the whole batch to Logger.OptimisticConcurrencyException and only the errored entries to DbUpdateConcurrencyException

@JoasE JoasE changed the title WIP: add transactional batch support to cosmos provider Add transactional batch support to cosmos provider Sep 9, 2025
@JoasE JoasE marked this pull request as ready for review September 9, 2025 11:52
@JoasE JoasE requested a review from a team as a code owner September 9, 2025 11:52
@JoasE
Copy link
Contributor Author

JoasE commented Sep 9, 2025

Let me know if I should rebase my changes to be a single commit with a better description

@JoasE
Copy link
Contributor Author

JoasE commented Sep 11, 2025

@AndriySvyryd Can I get a review on this? No rush! Just trying to make sure it isn't missed/buried. Excited to see what you think

/// <param name="containerId">The ID of the Cosmos container being queried.</param>
/// <param name="partitionKeyValue">The key of the Cosmos partition that the query is using.</param>
/// <param name="logSensitiveData">Indicates whether the application allows logging of sensitive data.</param>
public CosmosItemReadExecutedEventData(
Copy link
Member

Choose a reason for hiding this comment

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

There's no need to introduce a new DTO with the same shape as an existing one (CosmosItemCommandExecutedEventData)

context.Customers.Add(new Customer { Id = "4", PartitionKey = "2" });
context.CustomersWithTrigger.Add(new CustomerWithTrigger { Id = "4", PartitionKey = "2" });

await Assert.ThrowsAnyAsync<InvalidOperationException>(() => context.SaveChangesAsync());
Copy link
Member

Choose a reason for hiding this comment

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

Assert the exception message for all InvalidOperationException caught in this class


using System.Collections.Generic;
using System.Net;
using System.Runtime.InteropServices;
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I am using CollectionsMarshal.GetValueRefOrAddDefault on a dictionary

Copy link
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

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

@JoasE
Copy link
Contributor Author

JoasE commented Sep 12, 2025

@AndriySvyryd Thanks for the review! Sorry about the failing KeyValue tests! They failed for me locally with another error, but did the same on main. I assumed it was passing in the cloud since the azure pipeline succeeded, not knowing those don't run the tests. I've reset the data in my local emulator and can run the KeyValue tests now. I still have 4 other failing tests locally (on main), but these appear to have succeeded in the github action, as I couldn't find them in the test log I downloaded.

@JoasE JoasE requested a review from AndriySvyryd September 12, 2025 07:40
@AndriySvyryd AndriySvyryd merged commit 52381be into dotnet:main Sep 12, 2025
7 checks passed
@AndriySvyryd
Copy link
Member

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants