drizzle-team / drizzle-team/drizzle-orm

[BUG]: subquery selection proxy object doesn't correctly handle `in` and `hasOwnProperty` lookups

Open
#4,188 0 comments 0 reactions 0 assignees View on GitHub
bug qb/crud
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?

0.39.3

### What version of `drizzle-kit` are you using?

0.30.4

### Other packages

_No response_

### Describe the Bug

Subquery objects created with `drizzle.select().from(...).as('alias')` don't correctly handle `in` and `hasOwnProperty` lookups.

```
const testSubquery = drizzle.select().from(table).as("alias");
const columnName = testSubquery.columnName; // not null
const testIs = "columnName" in testSubquery; // false
const testHasOwn = Object.prototype.hasOwnProperty(testSubquery, "columnName"); // also false

const testObj = Struct.pick(testSubquery, "columnName"); // {}
```

This breaks usage with some libraries that check for property existence with `in` before selecting a value, such as Effect's [Struct.pick](https://effect-ts.github.io/effect/effect/Struct.ts.html#pick).

I suspect this can be fixed by implementing [has](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/has) and [getOwnPropertyDescriptor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/getOwnPropertyDescriptor) in https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/selection-proxy.ts

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.