Skip to content

#grid Document View: first Add save should insert, not upsert #rdg #1153

Backlog

Description

Background

Copilot C5 reported that a first Add save can reach upsertDocument with _id: 0, false, "", or null, and that replaceOne(..., { upsert: true }) can silently overwrite a matching document.

The silent-overwrite behavior is already present on main for every truthy supplied _id: the Add save routes the supplied ID to replaceOne(..., { upsert: true }), so a matching existing document is overwritten. The old truthy check dropped the four falsy IDs instead of saving them; #1142 fixes that handling. The existing fix commit is 8cc23e1563bd2fedbb07514c3a8eb788c5c14b38. It consequently adds those four newly recognized falsy IDs to the pre-existing overwrite behavior while also fixing the higher-severity Edit-mode duplicate bug for falsy IDs.

C5 thread: #1142 (comment)

Option A

Route an explicit isNew value through the first Add-save path:

  1. A first Add save calls a new ClustersClient.insertDocument method using insertOne, rather than upsertDocument.
  2. A duplicate-key E11000 error is surfaced to the user and no stored document is altered.
  3. Subsequent saves use the _id returned from the insert, so they update the document rather than attempting a new insert.
  4. This addresses duplicate _id behavior independently for all ID values, and can use the dedicated insert path as the implementation of the existing TODO.

The existing TODO and upsert implementation are at src/documentdb/ClustersClient.ts#L1213, verified against base commit 52e1ce269bb044d61ccea82c5607343d3fc8d616. This is the follow-up issue for WI-R8 C5; no code change belongs to this issue unless it is implemented separately.

Acceptance notes

  • First Add save is insert-only.
  • Duplicate _id insertion reports MongoDB duplicate-key error E11000 without overwriting or deleting the existing document.
  • Generated or supplied _id from the successful insert is returned and used by later saves.
  • The follow-up does not revert or weaken Refresh Collection View with React Data Grid #1142’s falsy-ID handling.

Activity

  1. changed the title [-]Document View: first Add save should insert, not upsert[/-] [+]#grid Document View: first Add save should insert, not upsert[/+] on Dec 1, 2026
  2. tnaum-ms commented on Dec 1, 2026

    @tnaum-ms
    CollaboratorAuthor

    This is the explicit disposition of #1152 C5. Cover duplicate supplied IDs for both truthy and falsy values, assert that the existing stored document is untouched and the duplicate-key error is reported. Then cover a successful first insert with an explicit or generated ID followed by a second save that updates that same document. Preserve #1142's own-property check for _id; this is not the numeric-representation work in #1145/#1148. Do not silently turn a failed first insert into an update.

  3. changed the title [-]#grid Document View: first Add save should insert, not upsert[/-] [+]#grid Document View: first Add save should insert, not upsert #rdg[/+] on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions