Skip to content

[queryCompiler] ~ include: true, sometimes doesn't include #27240

@semoal

Description

@semoal

Bug description

Is a complex code to share but here are the logs of what we send to the prisma.transaction.findMany()

Transaction model:

model Transaction {
  id              String          @id @default(uuid()) @db.Uuid
  valueDate       DateTime        @db.Timestamptz(3)
  tradeDate       DateTime        @db.Timestamptz(3)
  settlementDate  DateTime?       @db.Timestamptz(3)
  orderDate       DateTime?       @db.Timestamptz(3)
  transactionType TransactionType
  quantity        Float
  amount          Float?
  amountUSD       Float?
  netAmount       Float?
  netAmountUSD    Float?
  ratio           Float?
  price           Float?
  fees            Float?
  expenses        Float?
  taxes           Float?
  exchangeRate    Float?
  accruedInterest Float?
  currency        String
  externalId      String?
  datafeed        Datafeed?
  warning         Boolean?
  instrumentId    String          @db.Uuid
  portfolioId     String?         @db.Uuid
  createdAt       DateTime        @default(now()) @db.Timestamptz(3)
  updatedAt       DateTime        @updatedAt @db.Timestamptz(3)
  instrument      Instrument      @relation(fields: [instrumentId], references: [id])
  portfolio       Portfolio?      @relation(fields: [portfolioId], references: [id])

  @@unique([externalId, datafeed])
  @@index([portfolioId, valueDate, transactionType])
  @@index([portfolioId, valueDate])
}
Found transaction with null instrument: {
  arguments: '{\n' +
    '  "where": {\n' +
    '    "valueDate": {\n' +
    '      "lte": "2022-11-23T00:00:00.000Z"\n' +
    '    },\n' +
    '    "portfolioId": {\n' +
    '      "in": [\n' +
    '        "436668fc-9d7e-4b9e-9fe6-92ee97bda314"\n' +
    '      ]\n' +
    '    }\n' +
    '  },\n' +
    '  "include": {\n' +
    '    "instrument": true\n' +
    '  },\n' +
    '  "orderBy": {\n' +
    '    "valueDate": "asc"\n' +
    '  }\n' +
    '}',
  transactions: [
    {
      id: 'b2e3e1d4-b591-4e0a-a75b-efe094f23707',
      instrumentId: 'f38c4376-c76d-417e-b33d-5650a7f2666e',
      instrument: null,
      portfolioId: '436668fc-9d7e-4b9e-9fe6-92ee97bda314',
      tradeDate: 2019-12-31T00:00:00.000Z,
      valueDate: 2019-12-31T00:00:00.000Z
    }
    {
      id: 'b212b4dc-a897-47f9-b48e-db27e3918d32',
      instrumentId: '1a2fc365-c205-40bd-ae89-09b6d47c27eb',
      instrument: [Object],
      portfolioId: '436668fc-9d7e-4b9e-9fe6-92ee97bda314',
      tradeDate: 2021-02-12T00:00:00.000Z,
      valueDate: 2021-02-12T00:00:00.000Z
    },
    {
      id: '0c18731b-44fa-4605-9785-a5a479f0829c',
      instrumentId: '1a2fc365-c205-40bd-ae89-09b6d47c27eb',
      instrument: [Object],
      portfolioId: '436668fc-9d7e-4b9e-9fe6-92ee97bda314',
      tradeDate: 2021-03-15T00:00:00.000Z,
      valueDate: 2021-03-15T00:00:00.000Z
    },
    {
      id: '236368d9-76e4-4306-8ba8-6fd230b6042d',
      instrumentId: '1a2fc365-c205-40bd-ae89-09b6d47c27eb',
      instrument: [Object],
      portfolioId: '436668fc-9d7e-4b9e-9fe6-92ee97bda314',
      tradeDate: 2021-04-14T00:00:00.000Z,
      valueDate: 2021-04-14T00:00:00.000Z
    },

Severity

⚠️ Major: Breaks core functionality (e.g., migrations fail)

Reproduction

Will try to isolate into an smaller app, i don't promise nothing, really sorry here. I know how this sucks.

Expected vs. Actual Behavior

Without query compiler all the rows have instrument populated

Frequency

Consistently reproducible

Does this occur in development or production?

Both development and production

Is this a regression?

Tried with 6.9.0.dev.22 and 6.8.2

Workaround

Don't use query compiler.

Prisma Schema & Queries

// Add relevant schema.prisma snippet
// Add relevant Prisma Client query

Prisma Config

// Add your `prisma.config.ts`

Logs & Debug Info

// Debug logs here

Environment & Setup

Node: v22.11.0

Prisma Version

6.8.2 and 6.9.0.dev.22

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions