Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

fix: make pre_hash optional and add row_id to UpsertDatatabaseRow - #1614

Open
davideconte wants to merge 1 commit into
AppFlowy-IO:mainfrom
davideconte:fix/upsert-optional-pre-hash
Open

fix: make pre_hash optional and add row_id to UpsertDatatabaseRow#1614
davideconte wants to merge 1 commit into
AppFlowy-IO:mainfrom
davideconte:fix/upsert-optional-pre-hash

Conversation

@davideconte

@davideconte davideconte commented Apr 19, 2026

Copy link
Copy Markdown

Summary

The endpoint currently requires a field which is used to derive the row's UUID via SHA256. This makes it impossible to update existing rows because:

  1. The is computed client-side as β€” no API exposes this for existing rows
  2. The endpoint returns 404

This PR fixes the issue by:

Changes

libs/shared-entity/src/dto/workspace_dto.rs

  • Changed from to (backward compatible)
  • Added optional field
  • Added documentation explaining the precedence logic

src/api/workspace.rs ( handler)

  • If is provided β†’ use it directly as the row UUID
  • If is provided β†’ compute UUID via SHA256 (existing behavior)
  • If neither β†’ generate a random UUID (new behavior)

This allows both creating new rows without a , and updating existing rows by passing the known .

Testing

  • Existing tests should pass (backward compatible β€” still works when provided)
  • New behavior verified by the AppFlowy MCP server

Summary by Sourcery

Make database row upserts support optional pre-hash values and direct row ID specification to enable both new row creation and updates of existing rows.

New Features:

  • Allow clients to specify an explicit row_id when upserting a database row, using it directly as the row UUID.
  • Support creating database rows without providing a pre_hash by generating a random UUID when neither row_id nor pre_hash is supplied.

Enhancements:

  • Make the pre_hash field in UpsertDatatabaseRow optional and document the precedence logic between row_id, pre_hash, and random UUID generation.

- pre_hash is now Option<String>: if None, a random UUID is generated
- New optional row_id field: if provided, use it directly as the row UUID
- This enables UPDATE operations when you know the row ID (e.g. from list)
- Backward compatible: existing clients that always pass pre_hash still work
@sourcery-ai

sourcery-ai Bot commented Apr 19, 2026

Copy link
Copy Markdown

Reviewer's Guide

Makes the UpsertDatatabaseRow DTO and handler more flexible by making pre_hash optional, introducing an explicit row_id override, and updating row ID derivation logic to support both existing dedup semantics and direct UUID-based addressing.

Class diagram for updated UpsertDatatabaseRow DTO

classDiagram
  class UpsertDatatabaseRow {
    +Option<String> pre_hash
    +Option<String> row_id
    +HashMap<String, serde_json::Value> cells
    +Option<String> document
  }
Loading

Flow diagram for updated row_id resolution in put_database_row_handler

flowchart TD
  A[put_database_row_handler receives UpsertDatatabaseRow] --> B{row_id provided?}
  B -- Yes --> C[Parse row_id as UUID]
  C --> H[Call upsert_database_row with row_id UUID]
  B -- No --> D{pre_hash provided?}
  D -- Yes --> E[Compute SHA256 of workspace_id + db_id + pre_hash]
  E --> F[Take first 16 bytes of hash as UUID]
  F --> H
  D -- No --> G[Generate new random UUID]
  G --> H[Call upsert_database_row with row_id UUID]
Loading

File-Level Changes

Change Details Files
Allow UpsertDatatabaseRow to carry either a pre_hash or a direct row_id and update handler logic to derive the row UUID accordingly while preserving existing SHA256 behavior.
  • Change pre_hash type from String to Option to make it optional while preserving its semantics when present.
  • Add an optional row_id field to the DTO to allow clients to specify an explicit UUID for the row being upserted.
  • Update the put_database_row_handler to first prefer an explicit row_id (parsed and validated as a UUID), then derive a UUID from pre_hash using the existing SHA256 scheme, and finally fall back to generating a random UUID when neither is provided.
libs/shared-entity/src/dto/workspace_dto.rs
src/api/workspace.rs

Possibly linked issues

  • #[FR] Make pre-hash row id optional: Yes. The PR makes pre_hash optional and adds random/explicit row_id, directly fulfilling the feature request.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The precedence behavior when both row_id and pre_hash are provided is implicit in the handler (prefers row_id), but not documented in the DTO comments; consider either explicitly documenting this precedence or rejecting requests that set both to avoid ambiguous usage.
  • You parse row_id from a String in the handler; if this type is only used internally (not a public API contract), you might simplify by making row_id: Option<Uuid> on UpsertDatatabaseRow to centralize validation and reduce parsing logic at the boundary.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The precedence behavior when both `row_id` and `pre_hash` are provided is implicit in the handler (prefers `row_id`), but not documented in the DTO comments; consider either explicitly documenting this precedence or rejecting requests that set both to avoid ambiguous usage.
- You parse `row_id` from a `String` in the handler; if this type is only used internally (not a public API contract), you might simplify by making `row_id: Option<Uuid>` on `UpsertDatatabaseRow` to centralize validation and reduce parsing logic at the boundary.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click πŸ‘ or πŸ‘Ž on each comment and I'll use the feedback to improve your reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants