# Bug 3417: Error when whereExists before where

- Status: closed
- Project: Zero
- Creator: @grgbkr
- Assignee: @grgbkr
- Labels: user-reported
- Created: 2025-01-14T19:04:58Z
- Modified: 2025-01-18T20:58:44Z
- URL: https://bugs.rocicorp.dev/p/zero/issue/3417

## Description

If a query has a whereExists before a where, for example:

z.query.issue.whereExists('creator').where('status', 'open');

errors occur in the whereExists operator.

This error is one of: 
1. Error: fetchNodeForRow returned unexpected row, expected { id: X, ...}, received { id: Y, ...}
2. Uncaught (in promise) Error: Unexpected undefined value
    at must (chunk-I5GSZARI.js:76:11)
    at #fetchNodeForRow (chunk-AII6TS5B.js:9331:77)

The error does not occur if the conditions are reversed, like:

z.query.issue.where('status', 'open').whereExists('creator');

Suggesting this is likely some issue with pipeline-builder.  

See report in discord: https://discord.com/channels/830183651022471199/1288232858795769917/1328496656517304455

## Comments (1)

### @tantaman — 2025-01-14T21:34:22Z

Very odd since I thought we always built the pipeline in a specific order, regardless of how things were ordered in the query builder.
