Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError since upgrade to prisma 2.29.0 #53

Closed
ansemjo opened this issue Aug 11, 2021 · 6 comments
Closed

TypeError since upgrade to prisma 2.29.0 #53

ansemjo opened this issue Aug 11, 2021 · 6 comments

Comments

@ansemjo
Copy link

ansemjo commented Aug 11, 2021

I haven't looked into it very far yet but I've ran yarn upgrade earlier today, which updated both @prisma/client and prisma from 2.28.0 to 2.29.0. Trying to login or really just visiting any site which requires a session now results in the following error:

get(): TypeError: Cannot read property 'data' of undefined
TypeError: Cannot read property 'data' of undefined
    at PrismaSessionStore.<anonymous> (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:301:74)
    at step (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:61:23)
    at Object.next (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:42:53)
    at fulfilled (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:33:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Reverting these two packages to ~2.28.0 fixes the issue again.

For reference, my database model and initialization code
model Session {
  id        String   @id
  sid       String   @unique
  data      String
  expiresAt DateTime
}
return Session({
    name: SessionCookie,
    cookie: {
      maxAge: 7 * 24 * 60 * 60 * 1000, // ms, 7 days
      sameSite: "strict",
      secure: "auto",
    },
    secret: key,
    resave: false,
    saveUninitialized: false,
    unset: "destroy",
    store: new PrismaSessionStore(prisma, {
      checkPeriod: 10 * 60 * 1000, // ms, 10 minutes
      dbRecordIdIsSessionId: true,
      dbRecordIdFunction: undefined,
    }),
  });

It appears that it is this line that throws:

const result = this.serializer.parse(session.data ?? '{}') as SessionData;

Since it tries to lookup a specific sid, I tried to clear cookies but that didn't help. Running the query manually returns null, which should properly return from the function before trying to parse anything?

> prisma.session.findUnique({ where: { sid: "something" }}).then(res => console.log(res));
Promise { <pending> }
> null
@ansemjo
Copy link
Author

ansemjo commented Aug 11, 2021

I've used the high art of console.log-debugging .. and indeed the session object is somehow undefined

the diff
*** /tmp/tmp-priceless-euler/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js	2021-08-11 08:38:53.209000000 +0200
--- node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js	2021-08-11 15:38:11.431780377 +0200
***************
*** 283,286 ****
--- 283,287 ----
              var session, result;
              var _a;
+             console.log("DEBUG session.get()", sid);
              return __generator(this, function (_b) {
                  switch (_b.label) {
***************
*** 289,299 ****
--- 290,303 ----
                          if (!(_b.sent()))
                              return [2 /*return*/, callback === null || callback === void 0 ? void 0 : callback()];
+                         console.log("DEBUG case1: prisma.session.findUnique({ where: { sid:", sid, "} })")
                          return [4 /*yield*/, this.prisma.session
                                  .findUnique({
                                  where: { sid: sid },
                              })
+                                 .then(res => { console.log("DEBUG prisma result:", res); return res; })
                                  .catch(function () { return null; })];
                      case 2:
                          session = _b.sent();
+                         console.log("DEBUG case2: session is", session);
                          if (session === null)
                              return [2 /*return*/, callback === null || callback === void 0 ? void 0 : callback()];
DEBUG session.get() c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc
DEBUG case1: prisma.session.findUnique({ where: { sid: c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc } })
DEBUG case2: session is undefined
app:error TypeError: Cannot read property 'data' of undefined 
 TypeError: Cannot read property 'data' of undefined
    at PrismaSessionStore.<anonymous> (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:305:74)
    at step (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:61:23)
    at Object.next (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:42:53)
    at fulfilled (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:33:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
prisma:query BEGIN; [] 0 ms
prisma:query SELECT "public"."Session"."id", "public"."Session"."sid", "public"."Session"."data", "public"."Session"."expiresAt" FROM "public"."Session" WHERE "public"."Session"."sid" = $1 LIMIT $2 OFFSET $3; ["c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc",1,0] 1 ms
prisma:query ROLLBACK; [] 0 ms
GET 500 /api/login 52b 12.787ms 2021-08-11T13:33:07.384Z
Error: 
Invalid `prisma.session.delete()` invocation:


  An operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.
    at cb (/path/to/project/node_modules/@prisma/client/runtime/index.js:35943:17)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Apparently it's Schrödinger's session though. If I add a .then() after the prisma query, the session object becomes null:

DEBUG session.get() c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc
DEBUG case1: prisma.session.findUnique({ where: { sid: c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc } })
prisma:query SELECT "public"."Session"."id", "public"."Session"."sid", "public"."Session"."data", "public"."Session"."expiresAt" FROM "public"."Session" WHERE "public"."Session"."sid" = $1 LIMIT $2 OFFSET $3; ["c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc",1,0] 1 ms
DEBUG prisma result: null
DEBUG case2: session is null
GET 403 /api/login 12b 10.606ms 2021-08-11T13:38:22.191Z

Logging in still does not work though because I get a different error later on:

app:auth { id: 1, name: 'Max Mustermann', pkz: null, type: 'local' }
prisma:query BEGIN; [] 0 ms
prisma:query SELECT "public"."Session"."id" FROM "public"."Session" WHERE "public"."Session"."sid" = $1; ["84zxpnfBNyp-f64tQz2EELAQBTRfu9o9"] 1 ms
prisma:query ROLLBACK; [] 0 ms
(node:456710) UnhandledPromiseRejectionWarning: Error: 
Invalid `prisma.session.update()` invocation:


  An operation failed because it depends on one or more records that were required but not found. Record to update not found.
    at cb (/path/to/project/node_modules/@prisma/client/runtime/index.js:35943:17)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

I am a little lost .. is this possibly a prisma issue?

@kleydon
Copy link
Owner

kleydon commented Aug 15, 2021

Not sure... Haven't seen anything like this yet.

Internally, prisma-session-store has been using an older version of Prisma; I've just updated that, and hope the PR will complete this week.

Perhaps this will improve matters?

@ansemjo
Copy link
Author

ansemjo commented Aug 15, 2021

Aye. I've subscribed to its merging and will try again then. (just for reference: #55 appears to be the PR in question)

@kleydon
Copy link
Owner

kleydon commented Aug 15, 2021

👍

@ansemjo
Copy link
Author

ansemjo commented Aug 16, 2021

I noticed your PR updated prisma to 2.29.1 (I've used 2.29.0 above). Looking at the release notes, there's a link to this issue: prisma/prisma#8718. I'd say this fits my observation of a "Schrödinger's session" above.

And indeed, simply updating to @prisma/client and prisma to 2.29.1 fixes this issue for me.

Thus I'm closing this. It appears to have been a prisma issue indeed.

@ansemjo ansemjo closed this as completed Aug 16, 2021
@kleydon
Copy link
Owner

kleydon commented Aug 16, 2021

@ansemjo Glad to hear its resolved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants