Skip to content

Nothing refuses a Mongo variant field with the same name as a base field #30472

Open

Description

@wmadden-electric

What a user sees. A Mongo variant model (@@base(Asset, "photo")) can declare a field with the same name as a field of its base model, and nothing reports it. If the two have different types, the ORM writes and reads that field through .variant(...) with the variant's codec, while the collection validator derived from the contract keeps the base field's type. A write the ORM accepts can then fail with Document failed validation. No committed contract has such a field today.

Where. Mongo PSL interpretation of @@base in packages/2-mongo-family/2-authoring/contract-psl/src/interpreter.ts (and the TypeScript builder's variant handling); the ORM merge of base and variant fields in packages/2-mongo-family/5-query-builders/orm/src/collection.ts.

Likely fix. Refuse a variant field whose name matches a base field during contract emit, with a diagnostic at the variant field naming both models. If redeclaring a base field with the same type should be allowed, refuse only a differing type.

Where it came from. #30439.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions