Skip to content

fix: include workspace id in processTransactionTrace query to prevent global update error#710

Merged
antoinedc merged 1 commit into
developfrom
fix/sentry-708
Mar 15, 2026
Merged

fix: include workspace id in processTransactionTrace query to prevent global update error#710
antoinedc merged 1 commit into
developfrom
fix/sentry-708

Conversation

@claude

@claude claude Bot commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #708

Sentry Error: You attempted to save an instance with no primary key, this is not allowed since it would result in a global update
Root Cause: The Sequelize include query for the workspace object was missing the 'id' attribute, causing the workspace instance to have no primary key set.
Fix: Added 'id' to the workspace attributes list in the include query, ensuring the workspace instance has its primary key for proper targeted updates.
Regression: Not a regression - this appears to be a new error triggered when RPC endpoints return errors that make the code think they don't support debug_traceTransaction.

Test plan

  • Relevant unit tests pass (processTransactionTrace.test.js)
  • Fix addresses the root cause by ensuring workspace instances have primary keys for updates

🤖 Generated with Claude Code

… global update error

The workspace.update() calls were failing because the Sequelize include
query was missing the 'id' attribute, causing the workspace instance
to have no primary key. This resulted in Sequelize throwing the error:
"You attempted to save an instance with no primary key, this is not
allowed since it would result in a global update".

Adding the 'id' to the attributes list ensures the workspace instance
has its primary key set, allowing proper targeted updates.

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Mar 15, 2026

Copy link
Copy Markdown

Greptile Summary

This PR is a targeted one-line bug fix that adds 'id' to the Sequelize attributes list when fetching the associated Workspace in processTransactionTrace.js, resolving a Sentry crash where Sequelize threw "You attempted to save an instance with no primary key" whenever workspace.update({ tracing: null }) was called on the fetched instance.

Key changes:

  • Added 'id' to the Workspace attributes projection in the Transaction.findByPk include, ensuring Sequelize populates the primary key on the workspace instance so subsequent .update() calls target the correct row rather than triggering a global update guard.

Notes:

  • The fix is minimal and correct — all three workspace.update() call-sites (lines 73, 84, 89) are covered by this single change.
  • The Explorer include still only exposes ['shouldSync'] without id, but since no .update() is ever called on the explorer instance in this job, that is not a problem.
  • Existing unit tests already use a workspace mock with id: 1, so they remain valid and continue to pass with the fix in place.

Confidence Score: 5/5

  • This PR is safe to merge — it is a minimal, well-understood one-line fix with no side effects.
  • The change adds a single attribute ('id') to a Sequelize projection. It directly addresses the documented root cause (missing primary key on the workspace instance), does not alter any business logic, and is consistent with how every other job in the codebase already queries workspace attributes. The existing test suite exercises all relevant code paths.
  • No files require special attention.

Important Files Changed

Filename Overview
run/jobs/processTransactionTrace.js Adds 'id' to the Workspace attributes list in the Sequelize include, fixing a Sequelize "no primary key" crash that occurred when calling workspace.update() on the fetched instance. Change is minimal, targeted, and correct.

Sequence Diagram

sequenceDiagram
    participant Job as processTransactionTrace
    participant DB as Transaction (DB)
    participant WS as Workspace (DB)
    participant T as Tracer (RPC)

    Job->>DB: findByPk(transactionId)<br/>include workspace { id, public, rpcServer, ... }
    DB-->>Job: transaction + workspace instance (with id ✓)
    
    alt Missing transaction
        Job-->>Job: return 'Cannot find transaction'
    else Not public
        Job-->>Job: return 'Not allowed on private workspaces'
    else No explorer / sync disabled / RPC unreachable
        Job-->>Job: return early guard
    else No subscription / tracing disabled
        Job-->>Job: return early guard
    end

    Job->>T: new Tracer(rpcServer, db, tracing)
    Job->>T: tracer.process(transaction)
    T-->>Job: parsedTrace or error

    alt tracer.error (RPC does not support debug_traceTransaction)
        Job->>WS: workspace.update({ tracing: null })
        Note right of WS: Requires workspace.id (this fix)
    else parsedTrace available
        Job->>DB: transaction.safeCreateTransactionTrace(parsedTrace)
        DB-->>Job: trace result
        alt trace error / not enabled error
            Job->>WS: workspace.update({ tracing: null })
            Note right of WS: Requires workspace.id (this fix)
        end
    end
Loading

Last reviewed commit: bb36dea

@antoinedc antoinedc merged commit 0a9e2c8 into develop Mar 15, 2026
9 checks passed
@antoinedc antoinedc deleted the fix/sentry-708 branch March 15, 2026 23:16
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.

Error: You attempted to save an instance with no primary key, this is not allowed since it would result in a global update

1 participant