Skip to content

Docs bug: const total = 0 mutated in "Metrics removed" example (Upgrade to v7) #7810

@serhii-sierov-crest

Description

@serhii-sierov-crest

Summary

The totalQueries counter example in the "Metrics removed" section of the Upgrade to Prisma ORM v7 guide declares total with const but then attempts to reassign it, which will throw a TypeError: Assignment to constant variable at runtime (and fail to compile under TypeScript).

Location

Current (broken) code

const total = 0;
const prisma = new PrismaClient().$extends({
  client: {
    $log: (s: string) => console.log(s),
    async $totalQueries() {
      return total;
    },
  },
  query: {
    $allModels: {
      async $allOperations({ query, args }) {
        total += 1;          // ❌ Cannot assign to `total` because it is a constant
        return query(args);
      },
    },
  },
});

Expected fix

Change const to let:

let total = 0;

Why this matters

This is the example users are directed to when replacing the removed Metrics preview feature, so anyone copy-pasting it as a starting point will hit an immediate runtime/compile error. It also undermines confidence in the migration guide at exactly the moment users are doing a major version upgrade.

Additional notes

  • The snippet also uses $allModels, which scopes the counter to model operations only - raw queries ($queryRaw, $executeRaw) won't be counted. Worth a brief note if the intent is a true "total queries" counter.

Metadata

Metadata

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