You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reading a polymorphic Mongo collection without .variant(...) returns variant-only fields undecoded #30471
What a user sees. For a model with @@discriminator and variant models declared with @@base, a read through the base collection (db.assets.all(), without .variant('Photo')) returns each document's variant-only fields exactly as the driver read them. A variant ObjectId field comes back as an ObjectId instance rather than a hex string, a Decimal128 as the driver's class rather than decimal text, and a Json field is not checked. Reads and writes through .variant(...) use the variant's codecs.
Where.packages/2-mongo-family/5-query-builders/orm/src/collection.ts: without a variant, the result shape is built from the base model's fields only (contractModelToMongoResultShape in packages/2-mongo-family/5-query-builders/query-builder/src/result-shape.ts), and the row decoder copies fields that are not in the shape unchanged (packages/2-mongo-family/7-runtime/src/codecs/decoding.ts).
Likely fix. Decode each row by its discriminator: build one result shape per variant (base fields plus that variant's fields) and pick the shape from the row's discriminator value, falling back to the base shape for an unknown value. Add an integration test that reads a mixed collection without .variant(...).
Where it came from.#30439, whose review found and fixed the .variant(...) case (the ORM skipped codecs on variant-only fields entirely) and recorded this one.
Activity