[BUG]: calling $count
on a replica using withReplicas
throws a TypeError
#4039
Labels
bug
Something isn't working
Report hasn't been filed before.
What version of
drizzle-orm
are you using?0.39.1
What version of
drizzle-kit
are you using?0.30.4
Other packages
No response
Describe the Bug
When resolving
$count
on a client with replicas, it results in a TypeError with message:Cannot read properties of undefined (reading 'session')"
The stack traces back to this line where
this
is undefined because thethis
context is likely not bound properly:drizzle-orm/drizzle-orm/src/pg-core/db.ts
Line 152 in 5ffd0bd
I'm wondering if this is because calling
withReplica
returns a plain object without the associated session object.drizzle-orm/drizzle-orm/src/pg-core/db.ts
Lines 671 to 689 in 5ffd0bd
Or whether calling
getReplicas.$count(...args)
is not binding the underlying replicaPgDatabase
instance tothis
.drizzle-orm/drizzle-orm/src/pg-core/db.ts
Line 659 in 5ffd0bd
If this is indeed the issue, the bug most likely exists for all dialects and not just Postgres.
I'm beginning to wonder if
withReplica
needs to return a class that extendsPgDatabase
(or equivalent in each dialect) that contains$primary
property among others.This is something that didn't grab my attention when I submitted #3952.
@AndriiSherman, @Sukairo-02: I'll be happy to submit a PR based on the outcomes of the discussion here.
The text was updated successfully, but these errors were encountered: