drizzle-team / drizzle-team/drizzle-orm
[BUG]: Inaccurate error message when selecting non-existent nested fields with query v2 API
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [x] I have verified that the bug I'm about to report hasn't been filed before.
### What version of `drizzle-orm` are you using?
1.0.0-beta.15-859cf75
### What version of `drizzle-kit` are you using?
1.0.0-beta.15-859cf75
### Other packages
_No response_
### Describe the Bug
Im using the standard pg driver and cannot confirm that this is reproducible with other drivers.
Considering the following query with a partial nested select including a field that doesn't exist (doesntExist):
```
db.query.user.findFirst({
with: {
post: {
columns: {
id: true,
doesntExist: true,
},
}
},
})
```
The query throws the following error:
```
{
"message":"Views with nested selections are not supported by the relational query builder",
"name":"DrizzleError",
"stack":"DrizzleError: Views with nested selections are not supported by the relational query builder
at PgDialect.nestedSelectionerror (file:///.../node_modules/drizzle-orm/pg-core/dialect.js:457:9)
at PgDialect.buildRqbColumn (file:///.../node_modules/drizzle-orm/pg-core/dialect.js:482:139)
at file:///.../node_modules/drizzle-orm/pg-core/dialect.js:503:33
at PgDialect.buildColumns (file:///.../node_modules/drizzle-orm/pg-core/dialect.js:519:4)
at PgDialect.buildRelationalQuery (file:///.../node_modules/drizzle-orm/pg-core/dialect.js:531:24)
at file:///.../node_modules/drizzle-orm/pg-core/dialect.js:548:29
at Array.map ()
at file:///.../node_modules/drizzle-orm/pg-core/dialect.js:540:32
at PgDialect.buildRelationalQuery (file:///...node_modules/drizzle-orm/pg-core/dialect.js:568:5)
at PgAsyncRelationalQuery._getQuery (file:///.../node_modules/drizzle-orm/pg-core/query-builders/query.js:35:23)
at PgAsyncRelationalQuery._toSQL (file:///.../node_modules/drizzle-orm/pg-core/query-builders/query.js:48:22)
at file:///.../node_modules/drizzle-orm/pg-core/async/query.js:15:39
at Object.startActiveSpan (file:///.../node_modules/drizzle-orm/tracing.js:7:9)
at PgAsyncRelationalQuery._prepare (file:///.../node_modules/drizzle-orm/pg-core/async/query.js:14:17)
at file:///.../node_modules/drizzle-orm/pg-core/async/query.js:35:16
at Object.startActiveSpan (file:///.../node_modules/drizzle-orm/tracing.js:7:9)"
}
```
The error is confusing and inaccurate, removing the doesntExist column from the select makes the code work. It should be changed to say something more along the lines of "column x not found on table/view y"
Contributor guide
Assessment
This issue has not been assessed yet.