Skip to content

feat Existence tests 2/4: scoped inner predicates — forward traversal, nesting, cross-scope guard #315

Description

@0x054

Parent

#311 (feat PRD: Existence tests — .exists() on reverse and M2M relations)

What to build

Scoped existence tests: the optional inner lambda, resolved as a full ferro predicate over the child model through the existing predicate resolver.

Everything a root predicate can do works inside the test: every operator, forward-FK traversal (rendered as joins inside the EXISTS subquery under unchanged ADR-0006 semantics — INNER at every hop, narrowing), &/|/~ composition, and nested existence tests to arbitrary depth (the exists node's inner tree is an ordinary condition tree, recursion for free).

Cross-scope references are rejected in this slice, the moment inner lambdas exist: an inner-tree leaf built from any proxy other than the inner lambda's own parameter, or a field proxy appearing as a comparison right-hand side, is a build-time error pointing at the deferred capability (#309). Silent misrendering is the failure mode this guard exists to prevent.

Demo: the full #308 query —

Txn.where(lambda t: t.category_id.in_(ids)
                  | t.lines.exists(lambda l: l.category_id.in_(ids)))

— a three-line split matches once, child-less roots survive the OR through the root branch, and keyset order_by + limit compose unchanged, on both backends.

Acceptance criteria

  • Inner lambda supports every operator and &/|/~ over the child model
  • Forward traversal inside the subquery renders joins within the EXISTS under ADR-0006 semantics (covered e2e)
  • Nested exists-in-exists works; depth 2 pinned e2e and by a golden vector
  • The feat OR-composition across a left-joined reverse child table (PRD from Pinch) #308 shape passes e2e on both backends: multi-line match → one root row; child-less root survives the OR; keyset composition
  • Explicit grouping semantics covered: t.lines.exists(lambda l: A & B) (one child matches both) vs t.lines.exists(A-test) & t.lines.exists(B-test) (some child each) return different, correct row sets
  • Cross-scope reference and field-proxy-as-RHS raise build-time errors naming feat Cross-scope correlation in existence tests (deferred from ADR-0007) #309 (messages pinned by tests)
  • Hand-authored golden vectors: scoped 1-hop exists, nested exists

Blocked by

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

    featureready-for-agentUnblocked and fully specified; an agent may claim it

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions