question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Combined filters bug

See original GitHub issue

Bug description

I would expect these two filters would be the same:

{
  id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
  OR: [
    {
      collaborators: {
        some: {
          userId: user.id,
          type: type === 'write' ? CollaborationType.WRITE : undefined,
        },
      },
    },
    {
      workspace: {
              members: {
                some: { userId: user.id, role: { not: WorkspaceRole.GUEST } },
              },
            },
    },
  ],
}
{
  OR: [
    {
      id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
      collaborators: {
        some: {
          userId: user.id,
          type: type === 'write' ? CollaborationType.WRITE : undefined,
        },
      },
    },
    {
      id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
      workspace: {
              members: {
                some: { userId: user.id, role: { not: WorkspaceRole.GUEST } },
              },
            },
    },
  ],
}

But the first one fails. Is it expected? Am I missing something?

How to reproduce

Combine a field filter with an OR filter

Expected behavior

No response

Prisma information

Not relevant

Environment & setup

  • OS: MacOS
  • Database: PostgreSQL
  • Node.js version: 14

Prisma Version

3.12.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
baptisteArnocommented, May 5, 2022

Thank you for investigating. Here is the partial DB schema:

model User {
  id                      String                    @id @default(cuid())
  createdAt               DateTime                  @default(now())
  updatedAt               DateTime                  @default(now()) @updatedAt
  lastActivityAt          DateTime                  @default(now())
  name                    String?
  email                   String?                   @unique
  emailVerified           DateTime?
  image                   String?
  accounts                Account[]
  sessions                Session[]
  typebots                Typebot[]
  folders                 DashboardFolder[]
  plan                    Plan?                      @default(FREE)
  stripeId                String?                   @unique
  credentials             Credentials[]
  customDomains           CustomDomain[]
  apiToken                String?
  CollaboratorsOnTypebots CollaboratorsOnTypebots[]
  company                 String?
  onboardingCategories    String[]
  graphNavigation         GraphNavigation?
  workspaces              MemberInWorkspace[]
}

model Workspace {
  id            String                @id @default(cuid())
  name          String
  icon          String?
  members       MemberInWorkspace[]
  folders       DashboardFolder[]
  typebots      Typebot[]
  createdAt     DateTime              @default(now())
  plan          Plan @default(FREE)
  stripeId      String?               @unique
  customDomains CustomDomain[]
  credentials   Credentials[]
  invitations   WorkspaceInvitation[]
}

model MemberInWorkspace {
  userId      String
  user        User          @relation(fields: [userId], references: [id], onDelete: Cascade)
  workspaceId String
  workspace   Workspace     @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
  role        WorkspaceRole

  @@unique([userId, workspaceId])
}

enum WorkspaceRole {
  ADMIN
  MEMBER
  GUEST
}

model WorkspaceInvitation {
  id          String        @id @default(cuid())
  createdAt   DateTime      @default(now())
  email       String
  workspaceId String
  workspace   Workspace     @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
  type        WorkspaceRole
}

model Typebot {
  id                 String                    @id @default(cuid())
  createdAt          DateTime                  @default(now())
  updatedAt          DateTime                  @default(now()) @updatedAt
  icon               String?
  name               String
  ownerId            String?
  owner              User?                      @relation(fields: [ownerId], references: [id], onDelete: Cascade)
  publishedTypebotId String?
  publishedTypebot   PublicTypebot?
  results            Result[]
  folderId           String?
  folder             DashboardFolder?          @relation(fields: [folderId], references: [id])
  blocks             Json[]
  variables          Json[]
  edges              Json[]
  theme              Json
  settings           Json
  publicId           String?                   @unique
  customDomain       String?                   @unique
  collaborators      CollaboratorsOnTypebots[]
  invitations        Invitation[]
  webhooks           Webhook[]
  workspaceId        String?
  workspace          Workspace?                @relation(fields: [workspaceId], references: [id], onDelete: Cascade)

  @@unique([id, ownerId])
}

model CollaboratorsOnTypebots {
  userId    String
  user      User              @relation(fields: [userId], references: [id], onDelete: Cascade)
  typebotId String
  typebot   Typebot           @relation(fields: [typebotId], references: [id], onDelete: Cascade)
  type      CollaborationType

  @@unique([userId, typebotId])
}

enum CollaborationType {
  READ
  WRITE
  FULL_ACCESS
}

0reactions
cprietocommented, May 24, 2022

Hi @baptisteArno I tried to reproduce your bug and I am confussed, with the schema provided in the current version (3.15) the generated queries for PostgreSQL are equivalent 😐

I will close this ticket, but please try with the latest version and if the problem persist, open the ticket and share the specific JS query you are trying (I tried using a query over Typebot) and I will take a look at it again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chaining multiple filter() in Django, is this a bug?
Multiple filter ()'s AND together when fields are on the same model, but then OR together when spanning relationships. – gerdemb. Nov 17,...
Read more >
Bug #431271 “crash after 'undo/redo' a (combined) filter effect ...
After the first crash, Inkscape no longer displays any image used in a new image filter without resetting 'preferences.xml'. console messages: terminate called ......
Read more >
Content pane + combined filters causes views "Illegal Choice" error ...
When using BEF in a "content pane" view with a full pager and combined filters, you get an error when switching pages.
Read more >
BUG : Combined Field filter ignores custom separator
BUG : Combined Field filter ignores custom separator. Tested in v.10.1.0. I have 2 dimensions: - FY (Financial Year) text datatype with ...
Read more >
Multiple Filter Not Working Properly - Power Platform Community
An Unexpected Error has occurred. Top Solution Authors (Last Month) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found