Skip to content

Duplicate Database Query in Test Runs API Endpoint #26974

@soumojit-D48

Description

@soumojit-D48

Bug Description

The GET /workflows/:workflowId/test-runs/:id endpoint makes two separate database queries when fetching a single test run - one for authorization check and one for retrieving the data. This is inefficient and can be optimized to use a single query.

To Reproduce

  1. Make a GET request to /workflows/:workflowId/test-runs/:id endpoint
  2. Observe that two database queries are executed:
    • First query: findOne in getTestRun() method for authorization
    • Second query: getTestRunSummaryById() to fetch the data with relations

Expected behavior

The endpoint should fetch the test run with a single database query that also handles authorization check.

Add a new repository method getTestRunSummaryByIdWithAuthorization that combines:

  1. Fetching the test run with relations (testCaseExecutions)
  2. Authorization check against allowed workflow IDs
  3. Calculation of finalResult

This reduces the endpoint from 2 database queries to 1.

Debug Info

The issue is in:

  • packages/cli/src/evaluation.ee/test-runs.controller.ee.ts - Line 57 (before fix)
  • packages/@n8n/db/src/repositories/test-run.repository.ee.ts - getTestRunSummaryById method

Operating System

Windows (development environment)

n8n Version

2.12.0

Node.js Version

24.14.0

Database

SQLite (default)

Execution mode

main (default)

Hosting

self hosted

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions