Skip to content

verify: origin.passthrough field type must match its source unless an explicit transform is declared #185

Closed

Description

@dmealing

Summary

A field.<T> that pulls its value from another field via origin.passthrough can declare a different <T> than its source and codegen accepts it silently. The projected field should be type-identical to its source unless an explicit transform attribute converts it. Add a validation-phase check that fails (or warns) when a passthrough field's declared type ≠ the source field's type and no transform is declared.

Motivating case

A downstream adopter migrated UUID columns from field.string { dbColumnType: uuid } to field.uuid. The source entity field was flipped correctly, but two view projections kept projecting it as field.string:

# source entity — migrated
- field.uuid: { name: currentLocationId }

# view projection — NOT migrated, silently accepted
- field.string:
    name: currentLocationId
    children: [ { origin.passthrough: { from: "acme::engine::GameCharacter.currentLocationId" } } ]

The generated view surfaces String? while the source is UUID?, which forces hand-written ?.toString() bridge code in the repositories and leaves the field String-typed end-to-end — the exact inconsistency the migration set out to remove. Nothing catches it: it's not a raw dbColumnType, so a dbColumnType-based lint can't see it; codegen just emits the declared (wrong) type; and it compiles + runs fine, so it's invisible until someone reads the generated view.

Proposed check

During validation (candidate home: ValidationPhase / Verify, alongside the existing projection handling in ProjectionMetaObject), for every field carrying an origin.passthrough child:

  1. Resolve the from: reference to the source field.
  2. If the passthrough field's own type (field.<T>, including array-ness / nullability shape) differs from the source field's type, fail with a clear message naming both sides — e.g. view field 'currentLocationId' (field.string) does not match its passthrough source GameCharacter.currentLocationId (field.uuid); declare field.uuid or add an explicit transform.
  3. Escape hatch: skip the check when the field declares an explicit transform attr that changes the type (this is the natural home for the transform concept in origin.expression: computed projection columns (post-1.0, additive) #159's origin.expression — a computed/converting projection is allowed to differ). Absent a transform, identical types are the invariant.

Why framework-level

A per-adopter CI lint can catch the raw field.string { dbColumnType: uuid } idiom, but it cannot see through origin.passthrough to know the projected type diverged from its source — the metadata model is the only place that knows both ends of the passthrough. This is a metamodel invariant ("a passthrough is type-preserving unless transformed"), so it belongs in the loader/verify, not in each adopter.

Related

Activity

  1. dmealing commented on Jul 8, 2026

    @dmealing
    MemberAuthor

    Decision (design finalized 2026-07-08)

    Implementing this, with three refinements to the spec above — grounded in the existing code:

    1. It's one universal invariant, not a new subsystem. A narrow version of this check already exists: ERR_PARAMETER_REF_PASSTHROUGH_TYPE_MISMATCH (validate-source-parameter-ref.ts) already does paramField.subType !== targetField.subType — but only for FR-015 stored-proc @parameterRef value-objects, so it can't see a object.projection view field (the motivating case). Rather than add a second overlapping check, generalize it: one ERR_PASSTHROUGH_TYPE_MISMATCH in the origin-paths validation pass (next to the existing _checkExtendsOriginAgreement, where @from already resolves to the source field node) covering projection / entity / value fields alike, and retire the narrow ERR_PARAMETER_REF_PASSTHROUGH_TYPE_MISMATCH (repointing its conformance fixture). Single invariant, no gaps.

    2. Match subType + array-ness; NOT nullability. A uuid projected as string, or a scalar projected as an array, is always a bug. But a view over an outer join legitimately widens a NOT NULL source column to nullable — requiring nullability-identical would false-positive on valid projections and threaten the repo's >15%-false-positive kill bar. So: fail on subType or isArray divergence; leave nullability alone.

    3. Escape hatch is a new @convert boolean attr ON origin.passthrough — NOT blocked on #159. The spec above tied the opt-out to origin.expression (#159), which is post-1.0 and unbuilt. Instead add @convert: true directly on origin.passthrough: an acknowledgement that the type deliberately differs, which suppresses the error. It does not generate a cast — the value flows through as today and the adopter owns any coercion. Real type-converting projections remain #159/origin.expression's job; a passthrough-only check naturally ignores that subtype when it lands. This unblocks #185 from unbuilt work while giving a sanctioned, honest opt-out.

    Hard fail (not warn): deterministic structural equality on resolved nodes with nullability excluded ⇒ ~empty false-positive set; matches its siblings (ERR_EXTENDS_ORIGIN_MISMATCH, ERR_ORIGIN_CARDINALITY).

    Cross-port: TS reference first (fixtures-first), then Python / C# / Java / Kotlin, gated by a new fixtures/conformance/ fixture + registry-conformance (the @convert attr). Breaking on upgrade for adopters with a divergent passthrough (the point — it's a latent bug; the error names both sides + the fix). CHANGELOG breaking note.

  2. dmealing commented on Jul 13, 2026

    @dmealing
    MemberAuthor

    Fixed and shipped in 0.15.17 (npm) / PyPI 0.15.10 / NuGet 0.15.8 / Maven 7.7.8.

    origin.passthrough is now type-preserving: a passthrough field whose declared type differs from its @from source fails to load with ERR_PASSTHROUGH_TYPE_MISMATCH, with @convert: true as the explicit opt-out. Registered in all five ports and cross-port registry-conformance gated. See the 0.15.17 CHANGELOG entry.

  3. added 3 commits that reference this issue on Jul 16, 2026
  4. added a commit that references this issue on Aug 5, 2026
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