nocobase/nocobase · error

The record does not exist

Error message

The record does not exist

What it means

SingleRelationRepository.update first fetches the related target record by the given filter/targetCollection. If no matching record exists, it throws 'The record does not exist' rather than silently returning. The association target row identified by your filter/query could not be loaded before applying values.

Source

Thrown at packages/core/database/src/relation-repository/single-relation-repository.ts:99

      transaction,
    });

    return true;
  }

  @transaction()
  @injectTargetCollection
  async update(options: UpdateOptions): Promise<any> {
    const transaction = await this.getTransaction(options);

    const target = await this.find({
      transaction,
      // @ts-ignore
      targetCollection: options.targetCollection,
    });

    if (!target) {
      throw new Error('The record does not exist');
    }

    await updateModelByValues(target, options?.values, {
      ...options,
      transaction,
    });

    if (options.hooks !== false) {
      await this.db.emitAsync(`${this.targetCollection.name}.afterUpdateWithAssociations`, target, {
        ...options,
        transaction,
      });
      const eventName = `${this.targetCollection.name}.afterSaveWithAssociations`;
      await this.db.emitAsync(eventName, target, { ...options, transaction });
    }

    return target;
  }

View on GitHub (pinned to fa42722fef)

Solutions

  1. Verify the record exists with a findOne/filter call using the same tk/filter before updating
  2. Correct the filterByTk / filter value or targetCollection option
  3. Handle the deleted-record case gracefully in the caller (create instead, or surface a 404)

Example fix

// before
await repo.update({ filterByTk: id, values }); // throws if deleted
// after
const exists = await repo.findOne({ filterByTk: id });
if (!exists) throw new NotFoundError(`Record ${id} not found`);
await repo.update({ filterByTk: id, values });
Defensive patterns

Strategy: try-catch

Validate before calling

const exists = await singleRepo.findOne({ filterByTk: id });
if (!exists) throw new NotFoundError(`Related record ${id} not found`);

Type guard

const hasTarget = async (repo, opts) => (await repo.findOne(opts)) !== null;

Try / catch

try { await singleRepo.update({ filterByTk: id, values }); } catch (e) { if (e.message === 'The record does not exist') { throw new NotFoundError(id); } throw e; }

Prevention

When it happens

Trigger: Calling singleRelationRepository.update({ filterByTk: id, values }) (or via relation field update) where the related record with that tk was deleted, never existed, or the filter matches nothing; wrong targetCollection option passed.

Common situations: Stale UI referencing a deleted record; race condition where the record was removed between listing and updating; using the wrong primary key value or wrong collection name; multi-tenant/filter scoping hiding the record.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of nocobase/nocobase@fa42722fef (2026-09-01). Data as JSON: /api/errors/e88850bcfb1b50fc. Report an issue: GitHub.