{"record":{"id":"9181ce6084901af5","repo":"hasura/graphql-engine","slug":"found-a-column-field-value-in-the-middle-of-a-orde","errorCode":null,"errorMessage":"Found a column field value in the middle of a order by target path: ${orderByElement.target_path}","messagePattern":"Found a column field value in the middle of a order by target path: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"dc-agents/reference/src/query.ts","lineNumber":475,"sourceCode":"\n      case 'single_column_aggregate':\n        return aggregates[orderByElement.target.column];\n\n      case 'star_count_aggregate':\n        return aggregates['count'];\n\n      default:\n        return unreachable(orderByElement.target['type']);\n    }\n  } else {\n    if (rows.length > 1)\n      throw new Error(\n        `Unexpected number of rows (${rows.length}) returned by order by element query`,\n      );\n\n    const fieldValue = rows.length === 1 ? rows[0][relationshipName] : null;\n    if (fieldValue === null || typeof fieldValue !== 'object')\n      throw new Error(\n        `Found a column field value in the middle of a order by target path: ${orderByElement.target_path}`,\n      );\n\n    const innerOrderByElement = {\n      ...orderByElement,\n      target_path: remainingPath,\n    };\n    return extractResultFromOrderByElementQueryResponse(\n      innerOrderByElement,\n      fieldValue,\n    );\n  }\n};\n\nconst makeGetOrderByElementValue =\n  (\n    findRelationship: (relationshipName: RelationshipName) => Relationship,\n    applyRedaction: ApplyRedaction,","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/dc-agents/reference/src/query.ts#L457-L493","documentation":"While walking a multi-segment order-by target_path, each intermediate segment must resolve to an object (nested row) so traversal can continue. If an intermediate value is null or a non-object, a column value appeared in the middle of the path, which is invalid — only the final path segment may be a column value.","triggerScenarios":"An order_by with a target_path like ['a', 'b', 'c'] where traversing 'a' yields null or a scalar instead of a nested record — e.g. the first segment is a column name, or the relationship data is missing/null.","commonSituations":"Hand-written target_path arrays that start with a column instead of a relationship; null related rows (left-join style) in the static dataset; path segments that don't match any relationship name.","solutions":["Ensure target_path starts with relationship names and only the last segment names the target column.","If null related data is the cause, filter out rows with missing relationships before ordering or backfill the data.","Validate the path against the schema's relationship names before sending the query."],"exampleFix":"// before\norder_by: [{ target_path: ['name', 'artist'], target: { type: 'column', column: 'name' }, order: 'asc' }]\n\n// after\norder_by: [{ target_path: ['artist', 'name'], target: { type: 'column', column: 'name' }, order: 'asc' }]","handlingStrategy":"validation","validationCode":"const path = orderBy.target_path;\nif (path.slice(0, -1).some((seg, i) => !relationshipNames.includes(seg)))\n  throw new Error('intermediate order_by path segments must be relationships');","typeGuard":"const isObjectField = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object';","tryCatchPattern":null,"preventionTips":["Construct target_path as [relationship..., columnName] with the column last","Validate each intermediate segment against known relationship names before querying"],"tags":["hasura","data-connector","order-by","target-path"],"backgroundTag":"invalid-order-by-target-path","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}