Error: undefined is not an object
Getting the following error:
Seems to be occuring at the following code in my app:
Any idea what's occuring here? Doesn't happen with any other database calls including similar calls with the same
.where
arguments35 Replies
I've managed to track it down, it seems to be occuring in my
insert
statement here:
I'm still really unsure why this is happening, none of my other inserts fail. This is the schema also:
Other queries work?
Yeah everything else works. I have inserts working on other tables. It's only the sessions table
I've confirmed it's the insert too, not the query, that seems to work fine
And you did push/migrate the sessions table?
Yep, all up to date on migrate
What's confusing too is that this same code worked on a previous project, I just posted it over and it's giving this error now
That's very interesting. Are the Drizzle versions the same between projects?
orm and kit
Original working one is 0.38.2 on orm, 0.30.1 on kit. Current not working one is 0.38.3 on orm and 0.30.1 on kit
Can you try doing a test insert on that table in drizzle studio?
Don't think I actually have drizzle studio, I'll look into it
include in kit
npm drizzle-kit studio
you will need to specify you db connection credentials in drizzle.config.tsAlright, I'm out at the moment but I'll give it a shot as soon as I'm back
I tried studio, and unless I'm not doing the insert right, getting this
Setting the session_id as primary key in my schema lets me insert
However the actual error still occurs in the ORM
Oh duh I can't believe I didn't notice you were missing a PK on the table. I blame it being late.
So you did this?
And it's the exact same error?
Yeah haha. But yep, I did that, and same issue
Studio lets me insert but same error from the orm
It's strange cause my previous project's code worked even without the primary key, i'm very confused about it
And you're sure it's the insert that's throwing the error?
Yep, that's exactly what it's coming from. Commenting it out and everything works fine, i've got it in a try catch and it's absolutely where the error is coming from
can you change cuid2 for accountId to just be a varchar/text column?
on the sessionTable
Yeah I could, and just remove the account reference maybe?
You'd still need the reference for your session. I just curious is the column type of cuid2 is giving you trouble.
Hm, changed the type from cuid2 to text and ran push, no changes?
And the insert?
Same error 🙃
what values are you inserting?
Well this is the insert code
id
is a string, made from encoding the session token which is some crypto stuff
accountId
being the cuid2 string that's on the account (the test account i'm using has an ID of ss7f96cyakd6dy6k9y1idbhp
for example)
And createdAt/expiresAt are self explanatoryCan you enable logging on you drizzle initialization?
const db = drizzle({ logger: true });
Yup I can
I do
const db = drizzle(...)
in every file I use the db, do I have to throw logger on all of them or just the one in the index file?Is there some specific reason you aren't using just one global initialization?
Not really, might quickly change that
I would recommend that. Bound to cause issues in the future if it isn't already
Yeah, uhh... it seems using one global one fixed it, insert just worked fine
Guess that does make sense, lol. Strange it caused no problems on my other project but I'll keep that in mind for the future
Perfect. Glad that simple change fix it. I'm sure there are a dozen little edge cases where a non global db client will or won't work. But in the long run you can always bet on it causes a problem
Yeah, pretty clear there haha. On the upside, having a reliable server error for so long let me perfect my front end's error handling so I'll take that
I appreciate your help on it also
You're welcome