Skip to content

Redis driver: enforce unique ID constraint on create#310

Merged
hotlong merged 2 commits into
copilot/fix-action-run-issue-againfrom
copilot/fix-issues-in-action-run
Feb 2, 2026
Merged

Redis driver: enforce unique ID constraint on create#310
hotlong merged 2 commits into
copilot/fix-action-run-issue-againfrom
copilot/fix-issues-in-action-run

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 2, 2026

Redis driver was silently overwriting records on duplicate IDs instead of throwing. TCK test "should throw error on duplicate ID" failed.

Changes

RedisDriver.create() now uses SET ... NX to atomically check-and-set:

// Before: unconditional write
await this.client.set(key, JSON.stringify(doc));

// After: conditional write with duplicate detection
const result = await this.client.set(key, JSON.stringify(doc), { NX: true });
if (!result) {
    throw new Error(`Record with ID ${id} already exists in ${objectName}`);
}

Aligns behavior with other drivers (MongoDB, SQL) which reject duplicate primary keys.

Original prompt

引用: https://github.com/objectstack-ai/objectql/actions/runs/21579177618/job/62172785839#step:9:1


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectql Ready Ready Preview, Comment Feb 2, 2026 6:35am

Request Review

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issues in action run based on recent logs Redis driver: enforce unique ID constraint on create Feb 2, 2026
Copilot AI requested a review from hotlong February 2, 2026 06:33
@hotlong hotlong marked this pull request as ready for review February 2, 2026 06:51
Copilot AI review requested due to automatic review settings February 2, 2026 06:51
@hotlong hotlong merged commit c226f7a into copilot/fix-action-run-issue-again Feb 2, 2026
2 checks passed
@hotlong hotlong deleted the copilot/fix-issues-in-action-run branch February 2, 2026 06:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Enforces a uniqueness constraint for RedisDriver.create() by preventing silent overwrites when a record with the same ID already exists, aligning Redis driver behavior with other drivers and fixing the failing TCK case.

Changes:

  • Replace unconditional SET with conditional SET ... NX to avoid overwriting existing records
  • Throw an error when the key already exists (duplicate ID)

// Use SET with NX option to prevent overwriting existing records
const result = await this.client.set(key, JSON.stringify(doc), { NX: true });

if (!result) {
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

SET with NX typically returns 'OK' on success and null on failure (duplicate). Using if (!result) works, but it’s clearer/safer to check explicitly for the expected failure value (e.g., result === null) or success value (e.g., result !== 'OK') to avoid any ambiguity if return types change across Redis clients.

Suggested change
if (!result) {
if (result === null) {

Copilot uses AI. Check for mistakes.
const result = await this.client.set(key, JSON.stringify(doc), { NX: true });

if (!result) {
throw new Error(`Record with ID ${id} already exists in ${objectName}`);
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

Throwing a plain Error makes it harder for callers (and cross-driver behavior) to reliably detect a duplicate-ID condition. If the project has a standard duplicate/constraint error type or error code used by other drivers, throw that here (or wrap with a distinct name/code) so consumers can handle duplicates consistently without parsing the message.

Copilot uses AI. Check for mistakes.
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