Is there an existing issue for this?
Current behavior
When an EntitySchema is constructed with neither options.target nor options.name set, getRepositoryToken() silently produces the token string "undefinedRepository" instead of throwing.
Two branches earlier in the same function, a null/undefined entity correctly throws CircularDependencyException — same class of misconfiguration but handled inconsistently.
Affected file: lib/common/typeorm.utils.ts (the getRepositoryToken function)
Current code:
if (entity instanceof EntitySchema) {
return `${dataSourcePrefix}${
entity.options.target ? entity.options.target.name : entity.options.name
}Repository`;
}
Minimum reproduction code
This is a source-level defect found via static code review rather than a bug that needs a sample app to reproduce. The exact location is here:
|
if (entity instanceof EntitySchema) { |
|
return `${dataSourcePrefix}${ |
|
entity.options.target ? entity.options.target.name : entity.options.name |
|
}Repository`; |
|
} |
Steps to reproduce
- Call
getRepositoryToken(entitySchema) where entitySchema is an EntitySchema instance whose options object has neither target nor name defined.
- Observe that the function returns the string
"undefinedRepository" instead of throwing.
Expected behavior
Should throw a clear error when EntitySchema has neither target nor name defined, instead of silently producing an invalid token.
Proposed fix:
if (entity instanceof EntitySchema) {
const schemaName = entity.options.target
? entity.options.target.name
: entity.options.name;
if (!schemaName) {
throw new Error('EntitySchema must define either "target" or "name"');
}
return `${dataSourcePrefix}${schemaName}Repository`;
}
Package version
N/A — found via static code review of the repository at commit 3513624 (current master), not tied to a specific published release's reproduction.
NestJS version
N/A
Node.js version
N/A
In which operating systems have you tested?
N/A — static code review, not a runtime reproduction.
Other
I'd like to fix this — will open a PR shortly.
Is there an existing issue for this?
Current behavior
When an
EntitySchemais constructed with neitheroptions.targetnoroptions.nameset,getRepositoryToken()silently produces the token string"undefinedRepository"instead of throwing.Two branches earlier in the same function, a null/undefined
entitycorrectly throwsCircularDependencyException— same class of misconfiguration but handled inconsistently.Affected file:
lib/common/typeorm.utils.ts(thegetRepositoryTokenfunction)Current code:
Minimum reproduction code
This is a source-level defect found via static code review rather than a bug that needs a sample app to reproduce. The exact location is here:
typeorm/lib/common/typeorm.utils.ts
Lines 60 to 64 in 3513624
Steps to reproduce
getRepositoryToken(entitySchema)whereentitySchemais anEntitySchemainstance whoseoptionsobject has neithertargetnornamedefined."undefinedRepository"instead of throwing.Expected behavior
Should throw a clear error when
EntitySchemahas neithertargetnornamedefined, instead of silently producing an invalid token.Proposed fix:
Package version
N/A — found via static code review of the repository at commit
3513624(currentmaster), not tied to a specific published release's reproduction.NestJS version
N/A
Node.js version
N/A
In which operating systems have you tested?
N/A — static code review, not a runtime reproduction.
Other
I'd like to fix this — will open a PR shortly.