Repository navigation
Fix schema lookups and repository resolution to be resilient to mangling - #18
Merged
Merged
Conversation
kac-axelor
force-pushed
the
mangling
branch
3 times, most recently
from
March 20, 2026 07:34
8fd5440 to
35f3df8
Compare
Reproduce the bugs PR axelor#18 fixes against a real DataSource and Postgres container by mutating Function.name on entity classes before TypeORM metadata is built (the same effect bundlers have in production). Failing-on-broken-code (regression coverage): - Top-level isStringField: lowerCase/unaccent normalization is silently disabled because the schemaDefs lookup misses when targetName is mangled. SELECTs return zero rows instead of normalized matches. - Relation reference resolved by String field: `title: { select: { name "Jose" } }` throws "Referenced X not found" when the inverse entity is mangled, because the inner findOne hits the same isStringField bug and skips unaccent/lower wrapping. Passing-as-documentation: - ManyToOne reference, OneToMany collection-create, and relation-loader query under single-class mangling — these paths work incidentally because both sides read the mangled Function.name; the getRepository(rMeta.target) change is defensive. - Name collision (two entity classes forced to the same mangled name) — still resolves to the correct repository, confirming TypeORM's lookup is more resilient than feared.
ame-axelor
pushed a commit
that referenced
this pull request
May 20, 2026
…ing (#18) * Fix schema lookups and repository resolution to be resilient to name mangling * Fix schema lookups to use the active naming strategy for table name resolution * Add e2e tests for mangling resilience Reproduce the bugs PR #18 fixes against a real DataSource and Postgres container by mutating Function.name on entity classes before TypeORM metadata is built (the same effect bundlers have in production). Failing-on-broken-code (regression coverage): - Top-level isStringField: lowerCase/unaccent normalization is silently disabled because the schemaDefs lookup misses when targetName is mangled. SELECTs return zero rows instead of normalized matches. - Relation reference resolved by String field: `title: { select: { name "Jose" } }` throws "Referenced X not found" when the inverse entity is mangled, because the inner findOne hits the same isStringField bug and skips unaccent/lower wrapping. Passing-as-documentation: - ManyToOne reference, OneToMany collection-create, and relation-loader query under single-class mangling — these paths work incidentally because both sides read the mangled Function.name; the getRepository(rMeta.target) change is defensive. - Name collision (two entity classes forced to the same mangled name) — still resolves to the correct repository, confirming TypeORM's lookup is more resilient than feared.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JavaScript bundlers (webpack, turbopack) mangle class and function names in production builds to reduce bundle size:
This is harmless for most code, but breaks any code that reads a class name at runtime and compares it against a string baked in at compile time. Goovee ORM has several such patterns.
TypeORM's
EntityMetadataexposes two relevant properties:metadata.name/metadata.targetName— the class constructor name ((EntityClass as Function).name). Gets mangled.metadata.tableNameWithoutPrefix— the table name after applying the naming strategy, before any globalentityPrefix. Never mangled and stable for schema lookups regardless of DataSource prefix configuration.Similarly,
RelationMetadataexposes.name(the class constructor name, mangled) and.target(the class constructor reference, unaffected by mangling).Changes
1.
src/client/parser/context.ts—isStringFieldschema lookupisStringFieldis called during query parsing to decide whether to wrap a field inlower()/unaccent()for case-insensitive and accent-insensitive search. It looks up the entity's schema definition to check if a field is of typeString.The lookup was using
metadata.targetName(mangled) to find the matching entry inschemaDefs(which stores original names like"AOSPartner"). This silently failed in production, causingisStringFieldto always returnfalseand disabling normalization entirely.The fix resolves the schema entry using the active TypeORM naming strategy — the same logic TypeORM uses to derive the table name from
@Entity()decorator arguments — so the lookup is both mangling-resilient and correct regardless of which naming strategy is configured.2.
src/client/repository/repository.ts—getProtectedFieldsschema lookupgetProtectedFieldsenforces that fields markedinternal(never writable) orreadonly(not updatable after creation) are rejected on create and update operations. It also looks upschemaDefsby entity name.The lookup used
meta.name(mangled), so the entity was never found.getProtectedFieldswould return an empty set, silently bypassing all protected field checks.The fix passes the
repodirectly sogetProtectedFieldscan use the naming strategy from the live connection, matching entries the same way TypeORM resolves them.3.
src/client/repository/repository.tsandsrc/client/repository/query/query.ts— string-basedgetRepositorycallsThree call sites were passing a string (the class constructor name) to TypeORM's
getRepository. Under mangling, this works incidentally —rMeta.nameand the internally registered metadata name are both the same mangled value — but it is fragile. If two entity classes are ever assigned the same mangled name (possible across async chunks),getRepository(string)silently returns the wrong repository.The fix uses the class constructor reference instead, consistent with the already-correct pattern in
join-handler.ts(getRepository(relation.type)).Notes
The
portalproject also adds--no-manglingto itsnext buildcommand as a short-term mitigation while these fixes are released. That flag can be removed once this ORM version is consumed.