Skip to content

A Mongo field whose codec is unknown makes every write to its collection fail validation #30460

Open

Description

@wmadden-electric

What a user sees. When a Mongo PSL contract names a codec the codec lookup does not know (for example an extension codec whose pack is missing from the config), contract emit succeeds and the field is left out of the collection's $jsonSchema validator. The validator is closed with additionalProperties: false, so every document that carries the field is then rejected by MongoDB with Document failed validation, at write time, with no mention of the codec.

Where. fieldToBsonSchema in packages/2-mongo-family/2-authoring/contract-psl/src/derive-json-schema.ts returns undefined when codecLookup.targetTypesFor(codecId) is undefined, and the caller drops the property.

Likely fix. Report an unknown codec id as an authoring error during contract emit, naming the model, the field and the codec id, instead of emitting a validator that rejects the field. If there is a case where an unknown codec must be allowed, emit {} for the field so the validator does not reject it.

Where it came from. Pre-existing behaviour, recorded during #30396.

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