Skip to content

fix(tree-entity): tree entity schema propagation in internal TreeRepository methods - #12590

Merged
alumni merged 9 commits into
typeorm:masterfrom
xEverth:fix-tree-entity-schema-propagation-qb
Jun 24, 2026
Merged

alumni merged 9 commits into
typeorm:masterfrom
xEverth:fix-tree-entity-schema-propagation-qb

Conversation

@xEverth

@xEverth xEverth commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Description of change

This PR addresses a regression introduced in 0.3.29 affecting internal TreeRepository methods that use QueryBuilder when using a global schema configuration (DataSourceOptions.schema) or schema-qualified entities.
The PR includes working reproduction for the issue (checkout 94c1a97 ) and updates to entity metadata and functional tests for tree-entities using closure-table.
The applied resolution consists in adding option closureTableSchema to ClosureTreeOptions and giving it priority over the schema defined on the tree parent Entity or the dataSource's (similar approach to @andimattes 's #10743, addresses comments by maintainers). Should also address possible naming collisions (same closure table name, different schemas) by passing this.metadata.closureJunctionTable.target to queryBuilder's innerJoin's first argument.

It:
Fixes #12588
Fixes #10263

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links a relevant issue using a closing keyword:
    Fixes #NNNN, Closes #NNNN, or Resolves #NNNN
  • There are new or updated tests validating the change (tests/**.test.ts)
  • Documentation has been updated to reflect this change (docs/docs/**.md)

🛡️ Security fixes: Do not submit security fixes as public PRs — the diff exposes the vulnerability. Use GitHub Security Advisories instead.

@github-actions github-actions Bot added linked-issue PR references an issue possible-duplicate PR may duplicate an existing open PR labels Jun 18, 2026
@github-actions

Copy link
Copy Markdown

Other open PRs also reference #10263: #10743. Maintainers may want to coordinate.

@xEverth xEverth changed the title Fix tree entity schema propagation qb fix(tree-entity): Tree entity schema propagation in internal TreeRepository methods Jun 18, 2026
@xEverth xEverth changed the title fix(tree-entity): Tree entity schema propagation in internal TreeRepository methods fix(tree-entity): tree entity schema propagation in internal TreeRepository methods Jun 18, 2026
@xEverth

xEverth commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Extended test coverage to additional database drivers that support "schema" configuration.
Drivers not included in this validation:

  • Oracle: In Oracle, schemas correspond to users. While it may be possible to modify the Docker startup scripts (docker/oracle/startup) or provision users dynamically for tests, this would add significant complexity for a relatively targeted regression case. An alternative approach (creating users via an admin connection during tests) was also considered, but it appears brittle and difficult to maintain reliably in CI.
  • SAP HANA: Schema testing is currently not feasible in my environment. The driver rejects the configured schema with Invalid schema name MY_SCHEMA. Additionally, due to the high resource requirements and my local setup (Windows), I was unable to reliably run this configuration as noted in docker-compose.yaml.

The following drivers have been validated locally:

  • PostgreSQL
  • CockroachDB
  • MSSQL
  • Google Spanner

There is some intentional overlap in the test coverage, as TreeRepository behavior is exercised across entities with different schema configurations. This is primarily to ensure regression safety around schema-qualified closure tables and query builder aliasing behavior, at the cost of a slightly increased test runtime.

All tests are currently passing locally, no regressions have been observed relative to issue #10263, and it fixes the issue I reported in #12588 .

The core fix has been validated against the main drivers with schema support available in my setup (PostgreSQL, CockroachDB, MSSQL, Google Spanner). Oracle and SAP HANA were not included due to local/environmental constraints rather than any known incompatibility in the implementation.

If there are established CI patterns or infrastructure for improving coverage on those drivers, I’d be happy to align with them in a follow-up PR. Otherwise, I consider the regression addressed and this change safe to merge.

Thank you for reviewing.
Samuele

@xEverth
xEverth marked this pull request as ready for review June 18, 2026 15:56
@xEverth
xEverth force-pushed the fix-tree-entity-schema-propagation-qb branch from a0c5b5d to a1dee05 Compare June 18, 2026 16:04
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (4) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Schema test type mismatch 🐞 Bug ≡ Correctness
Description
In schema-handling.test.ts, defineSuite() only accepts constructors of Category |
CategoryWithSchema, but it is invoked with CategoryWithSchemaInClosure and
CategoryWithDifferentSchemaForClosure. This produces a TypeScript compile error and prevents the new
schema-handling regression suite from running.
Code

test/functional/tree-tables/closure-table/schema-handling/schema-handling.test.ts[R33-35]

+    const defineSuite = (
+        Entity: ClassConstructor<Category | CategoryWithSchema>,
+    ) => {
Evidence
The test helper restricts Entity to Category | CategoryWithSchema, but the same file later
passes two other constructors to it, which is not assignable to the declared union type.

test/functional/tree-tables/closure-table/schema-handling/schema-handling.test.ts[33-35]
test/functional/tree-tables/closure-table/schema-handling/schema-handling.test.ts[249-286]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`defineSuite` is typed as `ClassConstructor<Category | CategoryWithSchema>` but is called with additional entity classes, causing a TS compilation failure.
### Issue Context
This repository’s `tsconfig.json` includes `test/**`, so type errors in tests break `pnpm run compile` and therefore `pnpm test`.
### Fix Focus Areas
- test/functional/tree-tables/closure-table/schema-handling/schema-handling.test.ts[33-35]
### Suggested fix
Update the `defineSuite` parameter type to include all entities used in the file (e.g. add `CategoryWithSchemaInClosure` and `CategoryWithDifferentSchemaForClosure` to the union), or make it generic over a minimal required shape (e.g. `{ id: number; name: string; parentCategory?: any; childCategories?: any[] }`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Test entities type mismatch 🐞 Bug ≡ Correctness
Description
The new suiteSetup() types entities as Array> and forwards it into `createTestingConnections({
entities }), but TestingOptions.entities expects (string | Function | EntitySchema)[]`, making
this a likely TypeScript compile error in the test suite.
Code

test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[R134-152]

+    type ClassConstructor<T extends Object> = {
+        new (...args: unknown[]): T
+        name: string
+    }
+    const suiteSetup = async ({
+        entities,
+        dataSourceSchema,
+    }: {
+        entities: Array<string | ClassConstructor<any>>
+        dataSourceSchema: string | undefined
+    }): Promise<{ dataSources: DataSource[] }> => {
+        const harness = {
+            dataSources: await createTestingConnections({
+                entities,
+                enabledDrivers,
+                schema: dataSourceSchema,
+                schemaCreate: false,
+                dropSchema: false,
+            }),
Evidence
The test helper forwards a value typed as Array> into createTestingConnections(), whose options
type defines entities?: (string | Function | EntitySchema)[]. Since the repo’s tsconfig.json
includes test/** and pnpm test runs tsc, this mismatch can break compilation.

test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[134-155]
test/utils/test-utils.ts[41-60]
package.json[78-91]
tsconfig.json[21-34]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`createTestingConnections()` expects `TestingOptions.entities?: (string | Function | EntitySchema<any>)[]`, but the new schema-handling helper `suiteSetup()` defines `entities` as `Array<string | ClassConstructor<any>>` and passes it through directly. Because `ClassConstructor` (as declared) does not model `Function`, this can cause a TypeScript type error during `pnpm test` (which runs `tsc` over `test/**`).
## Issue Context
- `pnpm test` runs the `compile` script, which runs `tsc`, and the repo `tsconfig.json` includes the `test` directory.
## Fix
Change the `entities` param type in `suiteSetup()` to match the test harness type, e.g.
- Import `TestingOptions` from `test-utils` and use `NonNullable<TestingOptions["entities"]>`; or
- Simply type it as `(string | Function)[]` (or `(string | Function | EntitySchema<any>)[]` if needed).
## Fix Focus Areas
- test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[134-152]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. descandantColumnName misspelled ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The updated docs mention descandantColumnName, which is a misspelling and inconsistent with the
expected descendantColumnName naming. This can mislead users and violates the project's naming
conventions for identifiers shown in documentation.
Code

docs/docs/entity/4-tree-entities.md[146]

+You can specify the closure table name and/or closure table column names by setting optional parameter `options` into `@Tree("closure-table", options)`. `ancestorColumnName` and `descandantColumnName` are callback functions, which receive the primary column's metadata and return the column's name. `closureTableName` is the argument passed to the DataSource's naming strategy's closureJunctionTableName and defaults to parent entity's `tableNameWithoutPrefix`. `closureTableSchema` specifies the schema name where the closure table has to be saved in and defaults to the parent entity's schema (if provided to the parent Entity's decorator options) or the dataSource schema.
Evidence
PR Compliance ID 1 requires consistent naming for identifiers. The modified documentation line
includes the misspelled identifier descandantColumnName, which deviates from the standard
descendantColumnName naming used elsewhere and expected by users.

Rule 1: Consistent Naming Conventions
docs/docs/entity/4-tree-entities.md[146-146]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The docs reference the option `descandantColumnName`, which is misspelled and inconsistent with the actual/expected option name `descendantColumnName`.
## Issue Context
This appears in the Tree Entities documentation and can cause users to copy/paste an invalid option name.
## Fix Focus Areas
- docs/docs/entity/4-tree-entities.md[146-146]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

4. Closure join metadata collision 🐞 Bug ≡ Correctness
Description
TreeRepository now joins the closure table using closureJunctionTable.tableName, which makes
SelectQueryBuilder resolve the join target via DataSource.hasMetadata / entityMetadatasMap keyed
by metadata.target. Because closure-junction metadata is constructed with target: "" and later
normalized to target = tableName, multiple tree entities producing the same closure table name
(e.g., same base name in different schemas) can overwrite each other and cause joins to hit the
wrong schema/table.
Code

src/repository/TreeRepository.ts[R183-188]

 return this.createQueryBuilder(alias)
     .innerJoin(
-                    this.metadata.closureJunctionTable.tablePath,
+                    this.metadata.closureJunctionTable.tableName,
         closureTableAlias,
         joinCondition,
     )
Evidence
The join now passes a schema-less string, which causes QueryBuilder to attempt metadata resolution
by name/tableName. Closure-junction metadatas normalize target to tableName and DataSource
caches metadatas by target, so duplicates overwrite each other; find-by-string without a dot does
not disambiguate by schema.

src/repository/TreeRepository.ts[171-191]
src/repository/TreeRepository.ts[351-374]
src/query-builder/SelectQueryBuilder.ts[2091-2162]
src/data-source/DataSource.ts[662-707]
src/data-source/DataSource.ts[728-741]
src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts[37-54]
src/metadata/EntityMetadata.ts[1061-1076]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`TreeRepository` joins closure tables using `closureJunctionTable.tableName` (schema-less). This forces `SelectQueryBuilder` to resolve the join target as an entity via `DataSource.hasMetadata`, which can become ambiguous if multiple closure-junction metadatas share the same `tableName` (common in multi-schema setups where entities share names).
### Issue Context
- Closure-junction metadatas are created with `target: ""`, then `EntityMetadata.build()` normalizes `target` to `tableName`.
- `DataSource.entityMetadatasMap` is keyed by `metadata.target`, so duplicate closure table names will overwrite earlier entries.
- Join resolution for string targets without dots uses `metadata.name/tableName` matching, not schema, making it impossible to reliably pick the correct closure-junction metadata when duplicates exist.
### Fix Focus Areas
- src/repository/TreeRepository.ts[183-188]
- src/repository/TreeRepository.ts[366-371]
- src/query-builder/SelectQueryBuilder.ts[2107-2162]
- src/query-builder/JoinAttribute.ts[160-214]
- src/query-builder/QueryBuilderUtils.ts[11-27]
- src/data-source/DataSource.ts[662-707]
- src/data-source/DataSource.ts[728-741]
- src/metadata/EntityMetadata.ts[1061-1076]
- src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts[37-54]
### Suggested implementation direction
1. Make `JoinAttribute.relation` (or `QueryBuilderUtils.isAliasProperty`) treat strings like `schema.table` as a *table path* when the left side (`schema`) is not an existing query alias, instead of throwing.
2. Once schema-qualified joins are supported, change `TreeRepository` to join using `closureJunctionTable.tablePath` again (so schema is explicit and collisions in `entityMetadatasMap` are irrelevant).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Async tests not awaited ✓ Resolved 🐞 Bug ☼ Reliability
Description
The new test "should build the closure table in the correct schema" returns `dataSources.map(async
...)` without awaiting the resulting promises, so Mocha may complete the test before assertions run.
This can silently mask failures in closure-table schema creation/lookup.
Code

test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[R231-249]

+        it("should build the closure table in the correct schema", () =>
+            dataSources.map(async (dataSource) => {
+                const queryRunner = dataSource.createQueryRunner()
+                try {
+                    const entityMetadata =
+                        dataSource.getMetadata(CategoryWithSchema)
+                    const table = await queryRunner.getTable(
+                        [
+                            schemaName,
+                            dataSource.namingStrategy.closureJunctionTableName(
+                                entityMetadata.tableNameWithoutPrefix,
+                            ),
+                        ].join("."),
+                    )
+                    expect(table).not.to.be.undefined
+                } finally {
+                    await queryRunner.release()
+                }
+            }))
Evidence
The test directly returns the result of dataSources.map(async ...), which is Promise[], and is
not awaited/aggregated by Promise.all as done in other tests in the same file.

test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[211-250]
test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[59-91]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A mocha `it(...)` returns an array of promises (`dataSources.map(async ...)`) instead of a single awaited promise, meaning the test may finish before the async assertions execute.
### Issue Context
This makes the new schema-handling coverage unreliable and can lead to false positives.
### Fix Focus Areas
- test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[231-249]
### Suggested fix
Wrap the `map(async ...)` in `Promise.all(...)` and return/await it, e.g.:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. descandantColumnName typo in docs ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The updated tree-entities documentation uses the misspelled option name descandantColumnName,
which is inconsistent with the actual public API option descendantColumnName. This
documentation-only typo can mislead users and violates the project’s naming consistency
expectations.
Code

docs/docs/entity/4-tree-entities.md[146]

+You can specify the closure table name and/or closure table column names by setting optional parameter `options` into `@Tree("closure-table", options)`. `ancestorColumnName` and `descandantColumnName` are callback functions, which receive the primary column's metadata and return the column's name. `closureTableName` is the argument passed to the DataSource's naming strategy's closureJunctionTableName and defaults to parent entity's `tableNameWithoutPrefix`. `closureTableSchema` specifies the schema name where the closure table has to be saved in and defaults to the parent entity's schema (if provided to the parent Entity's decorator options) or the dataSource schema.
Evidence
PR Compliance ID 1 requires consistent naming conventions for new identifiers, and the cited
documentation line contains the misspelled descandantColumnName, deviating from the established
API naming. The provided context also notes that the real TypeScript interface option is
ClosureTreeOptions.descendantColumnName, confirming the docs and API are out of sync due to a
typo.

Rule 1: Consistent Naming Conventions
docs/docs/entity/4-tree-entities.md[146-146]
docs/docs/entity/4-tree-entities.md[146-154]
src/metadata/types/ClosureTreeOptions.ts[7-12]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The tree-entities documentation misspells the closure-table option name as `descandantColumnName`, but the correct public API option name is `descendantColumnName`.
## Issue Context
This is user-facing documentation for tree entities and should match the exported API option names; the actual interface uses `ClosureTreeOptions.descendantColumnName`, so users copying the docs will be misled.
## Fix Focus Areas
- docs/docs/entity/4-tree-entities.md[146-146]
- src/metadata/types/ClosureTreeOptions.ts[7-12]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (3)
7. Async test not awaited ✓ Resolved 🐞 Bug ☼ Reliability
Description
The test "should build the closure table in the correct schema" returns an array of Promises from
dataSources.map(async ...) instead of a single Promise, so Mocha won't await the async assertions
and the test can pass while failures happen later/unhandled. This weakens regression coverage for
the schema-handling behavior this PR is adding.
Code

test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[R231-249]

+        it("should build the closure table in the correct schema", () =>
+            dataSources.map(async (dataSource) => {
+                const queryRunner = dataSource.createQueryRunner()
+                try {
+                    const entityMetadata =
+                        dataSource.getMetadata(CategoryWithSchema)
+                    const table = await queryRunner.getTable(
+                        [
+                            schemaName,
+                            dataSource.namingStrategy.closureJunctionTableName(
+                                entityMetadata.tableNameWithoutPrefix,
+                            ),
+                        ].join("."),
+                    )
+                    expect(table).not.to.be.undefined
+                } finally {
+                    await queryRunner.release()
+                }
+            }))
Evidence
The new test uses dataSources.map(async ...) directly (returning an array of Promises), while
earlier tests in the same file correctly wrap async work in Promise.all(...) so Mocha awaits
completion.

test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[231-249]
test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[60-74]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A Mocha test returns an array of promises (from `map(async ...)`) rather than a single awaited promise, so the runner can complete the test before assertions execute.
### Issue Context
The file already uses `Promise.all(dataSources.map(async ...))` correctly in other tests; this one should follow the same pattern.
### Fix Focus Areas
- test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[231-249]
- test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[60-74]
### Suggested change
Change the test body to:
- `() => Promise.all(dataSources.map(async (dataSource) => { ... }))`
(or alternatively use a `for...of` loop with `await` inside and return a single async function).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. descandantColumnName typo in docs 📘 Rule violation ⚙ Maintainability
Description
The updated tree-entities documentation uses the misspelled option name descandantColumnName,
which is inconsistent with the actual public API option descendantColumnName. This
documentation-only typo can mislead users and violates the project’s naming consistency
expectations.
Code

docs/docs/entity/4-tree-entities.md[146]

+You can specify the closure table name and/or closure table column names by setting optional parameter `options` into `@Tree("closure-table", options)`. `ancestorColumnName` and `descandantColumnName` are callback functions, which receive the primary column's metadata and return the column's name. `closureTableName` is the argument passed to the DataSource's naming strategy's closureJunctionTableName and defaults to parent entity's `tableNameWithoutPrefix`. `closureTableSchema` specifies the schema name where the closure table has to be saved in and defaults to the parent entity's schema (if provided to the parent Entity's decorator options) or the dataSource schema.
Evidence
PR Compliance ID 1 requires consistent naming conventions for new identifiers, and the cited
documentation line contains the misspelled descandantColumnName, deviating from the established
API naming. The provided context also notes that the real TypeScript interface option is
ClosureTreeOptions.descendantColumnName, confirming the docs and API are out of sync due to a
typo.

Rule 1: Consistent Naming Conventions
docs/docs/entity/4-tree-entities.md[146-146]
docs/docs/entity/4-tree-entities.md[146-154]
src/metadata/types/ClosureTreeOptions.ts[7-12]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The tree-entities documentation misspells the closure-table option name as `descandantColumnName`, but the correct public API option name is `descendantColumnName`.
## Issue Context
This is user-facing documentation for tree entities and should match the exported API option names; the actual interface uses `ClosureTreeOptions.descendantColumnName`, so users copying the docs will be misled.
## Fix Focus Areas
- docs/docs/entity/4-tree-entities.md[146-146]
- src/metadata/types/ClosureTreeOptions.ts[7-12]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


9. Async test not awaited 🐞 Bug ☼ Reliability
Description
The test "should build the closure table in the correct schema" returns an array of Promises from
dataSources.map(async ...) instead of a single Promise, so Mocha won't await the async assertions
and the test can pass while failures happen later/unhandled. This weakens regression coverage for
the schema-handling behavior this PR is adding.
Code

test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[R231-249]

+        it("should build the closure table in the correct schema", () =>
+            dataSources.map(async (dataSource) => {
+                const queryRunner = dataSource.createQueryRunner()
+                try {
+                    const entityMetadata =
+                        dataSource.getMetadata(CategoryWithSchema)
+                    const table = await queryRunner.getTable(
+                        [
+                            schemaName,
+                            dataSource.namingStrategy.closureJunctionTableName(
+                                entityMetadata.tableNameWithoutPrefix,
+                            ),
+                        ].join("."),
+                    )
+                    expect(table).not.to.be.undefined
+                } finally {
+                    await queryRunner.release()
+                }
+            }))
Evidence
The new test uses dataSources.map(async ...) directly (returning an array of Promises), while
earlier tests in the same file correctly wrap async work in Promise.all(...) so Mocha awaits
completion.

test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[231-249]
test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[60-74]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A Mocha test returns an array of promises (from `map(async ...)`) rather than a single awaited promise, so the runner can complete the test before assertions execute.
### Issue Context
The file already uses `Promise.all(dataSources.map(async ...))` correctly in other tests; this one should follow the same pattern.
### Fix Focus Areas
- test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[231-249]
- test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[60-74]
### Suggested change
Change the test body to:
- `() => Promise.all(dataSources.map(async (dataSource) => { ... }))`
(or alternatively use a `for...of` loop with `await` inside and return a single async function).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Qodo Logo

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. descandantColumnName typo in docs 📘 Rule violation ⚙ Maintainability
Description
The updated tree-entities documentation uses the misspelled option name descandantColumnName,
which is inconsistent with the actual public API option descendantColumnName. This
documentation-only typo can mislead users and violates the project’s naming consistency
expectations.
Code

docs/docs/entity/4-tree-entities.md[146]

+You can specify the closure table name and/or closure table column names by setting optional parameter `options` into `@Tree("closure-table", options)`. `ancestorColumnName` and `descandantColumnName` are callback functions, which receive the primary column's metadata and return the column's name. `closureTableName` is the argument passed to the DataSource's naming strategy's closureJunctionTableName and defaults to parent entity's `tableNameWithoutPrefix`. `closureTableSchema` specifies the schema name where the closure table has to be saved in and defaults to the parent entity's schema (if provided to the parent Entity's decorator options) or the dataSource schema.
Evidence
PR Compliance ID 1 requires consistent naming conventions for new identifiers, and the cited
documentation line contains the misspelled descandantColumnName, deviating from the established
API naming. The provided context also notes that the real TypeScript interface option is
ClosureTreeOptions.descendantColumnName, confirming the docs and API are out of sync due to a
typo.

Rule 1: Consistent Naming Conventions
docs/docs/entity/4-tree-entities.md[146-146]
docs/docs/entity/4-tree-entities.md[146-154]
src/metadata/types/ClosureTreeOptions.ts[7-12]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The tree-entities documentation misspells the closure-table option name as `descandantColumnName`, but the correct public API option name is `descendantColumnName`.

## Issue Context
This is user-facing documentation for tree entities and should match the exported API option names; the actual interface uses `ClosureTreeOptions.descendantColumnName`, so users copying the docs will be misled.

## Fix Focus Areas
- docs/docs/entity/4-tree-entities.md[146-146]
- src/metadata/types/ClosureTreeOptions.ts[7-12]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Async test not awaited 🐞 Bug ☼ Reliability
Description
The test "should build the closure table in the correct schema" returns an array of Promises from
dataSources.map(async ...) instead of a single Promise, so Mocha won't await the async assertions
and the test can pass while failures happen later/unhandled. This weakens regression coverage for
the schema-handling behavior this PR is adding.
Code

test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[R231-249]

+        it("should build the closure table in the correct schema", () =>
+            dataSources.map(async (dataSource) => {
+                const queryRunner = dataSource.createQueryRunner()
+                try {
+                    const entityMetadata =
+                        dataSource.getMetadata(CategoryWithSchema)
+                    const table = await queryRunner.getTable(
+                        [
+                            schemaName,
+                            dataSource.namingStrategy.closureJunctionTableName(
+                                entityMetadata.tableNameWithoutPrefix,
+                            ),
+                        ].join("."),
+                    )
+                    expect(table).not.to.be.undefined
+                } finally {
+                    await queryRunner.release()
+                }
+            }))
Evidence
The new test uses dataSources.map(async ...) directly (returning an array of Promises), while
earlier tests in the same file correctly wrap async work in Promise.all(...) so Mocha awaits
completion.

test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[231-249]
test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[60-74]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
A Mocha test returns an array of promises (from `map(async ...)`) rather than a single awaited promise, so the runner can complete the test before assertions execute.

### Issue Context
The file already uses `Promise.all(dataSources.map(async ...))` correctly in other tests; this one should follow the same pattern.

### Fix Focus Areas
- test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[231-249]
- test/functional/metadata-builder/closure-junction-entity-metadata/closure-junction-metadata.test.ts[60-74]

### Suggested change
Change the test body to:
- `() => Promise.all(dataSources.map(async (dataSource) => { ... }))`
(or alternatively use a `for...of` loop with `await` inside and return a single async function).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Qodo Logo

@pkg-pr-new

pkg-pr-new Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm@12590
    

commit: c70a0da

Samuele added 6 commits June 19, 2026 09:19
Change introduced by MR !12110 breaks TreeRepository find methods whenever schema is specified in the dataSource options

Step 1: Rewriting of closure metadata tests from issue 10263 to monitor regressions
… the Tree decorator as typeorm#10743

Test locally with multiple database drivers which support the "schema" options
Update tests to remove driver-specific assumptions on closure table metadata's tablePath
Add functional test case for different schema options provided to the parent Entity and the Tree decorator
Promise in test was not correctly returned to test runner and may have caused a test hang. Test now uses constructed table path in metadata to check for existance rather than attempting to re-create it. fix docs typo.
… identity?

As soon as we pass a dotted string to innerJoin it's ambiguous and it resurfaces typeorm#12588. Passing the target trivializes the metadata lookup and still seems to work fine (all tests passing)
@xEverth
xEverth force-pushed the fix-tree-entity-schema-propagation-qb branch from cfb7a70 to 818198e Compare June 19, 2026 07:19
Samuele added 3 commits June 19, 2026 09:27
@xEverth

xEverth commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

If I'm not missing anything, I believe I've now addressed all review comments raised by Qodo, rebased the branch onto the latest commits on main, and run linting on all modified files.

The fix has been validated against the schema-supporting drivers available in my environment, all tests are passing locally, and I haven't observed any regressions relative to the reported issue.

When convenient, I'd appreciate another review from the maintainers to confirm that the implementation and test coverage are in good shape for merge.

Thank you for your time and feedback.
Samuele

@alumni alumni added the backport This fix should be backported to a previous version label Jun 19, 2026
@alumni
alumni merged commit 7fb7c2c into typeorm:master Jun 24, 2026
46 checks passed
@github-actions github-actions Bot added this to the 1.0 milestone Jun 24, 2026
alumni pushed a commit that referenced this pull request Jun 24, 2026
@alumni alumni removed the backport This fix should be backported to a previous version label Jun 24, 2026
@alumni

alumni commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the contribution @xEverth! I also backported it to v0, so it should be available soon on both major versions.

alumni pushed a commit that referenced this pull request Jun 24, 2026
@xEverth

xEverth commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review and for backporting it to v0 as well. I'm glad I could help, and I appreciate how quickly you got this addressed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linked-issue PR references an issue possible-duplicate PR may duplicate an existing open PR

2 participants