keystone icon indicating copy to clipboard operation
keystone copied to clipboard

Access denied on relationship fields connection

Open molotow11 opened this issue 1 year ago • 1 comments

I am trying to connect images to my object with sudo context. Used the following code:

  const context = req.KeystoneContext;
  const localDb = context.sudo().db;

  try {
    await localDb.Motif.updateOne({
      where: { sku: '027_DE' },
      data: { 
        isImagesMigrated: true, 
        images: { 
          connect: [
            { id: 17674 },
            { id: 17675 },
            { id: 17676 },
            { id: 17677 },
            { id: 17678 }
          ] 
        } 
      }
    });
  }
  catch (error) {
    console.log(error);
    console.log(error.extensions.debug);
  }

And I see the following error:

GraphQLError: An error occured while resolving relationship fields.
  - Motif.images: Access denied: You cannot connect that Image - it may not exist

I've tried to link it manually in admin panel then and it is all fine, so it looks like some bug there.

Screenshot from 2023-08-11 10-30-11

node: v16.20.1 keystone-6/core: v5.5.0

molotow11 avatar Aug 11 '23 03:08 molotow11

Updated: Direct prisma call works fine

molotow11 avatar Aug 11 '23 04:08 molotow11