Skip to content

@prisma/adapter-pg modifies node-postgres global type parsers #23505

Closed

Description

@matteosb

Bug description

Using the Prisma node-postgres adapter breaks queries run directly through node-postgres Pool and Client instances, even when the instance of Pool is not shared with the Prisma adapter. This is a problem for us because we'd like to use Prisma with the adapter, but we use node-postgres extensively, including for use-cases that Prisma doesn't support (streaming in particular).

Fortunately I think this should be very easy to fix: @prisma/adapter-pg registers its type parsers globally here. It could instead pass the type parsers to its queries explictly as described here.

How to reproduce

  1. import @prisma/adapter-pg
  2. Run a query via node-postgres

This script illustrates the problem with timestamp parsing and doesn't require a Prisma schema:

import { Pool } from "pg";

const pgPool = new Pool({ connectionString: process.env.DATABASE_URL });

async function main() {
  const before = await pgPool.query(`SELECT NOW() as ts`);
  console.log(
    "NOW() before @prisma/adapter-pg - value:",
    before.rows[0].ts,
    "type:",
    typeof before.rows[0].ts
  );

  require("@prisma/adapter-pg");

  const after = await pgPool.query(`SELECT NOW() as ts`);
  console.log(
    "NOW() after @prisma/adapter-pg - value:",
    after.rows[0].ts,
    "type:",
    typeof after.rows[0].ts
  );
}

main().finally(() => pgPool.end());

output:

NOW() before @prisma/adapter-pg - value: 2024-03-15T15:48:47.231Z type: object
NOW() after @prisma/adapter-pg - value: 2024-03-15 15:48:47.237668 type: string

Expected behavior

@prisma/adapter-pg shouldn't modify node-postgres's global type parsers. Instead, performIO could pass Prisma's custom type parsers as described in the node-postgres documentation.

Prisma information

This can be reproduced without any Prisma schema

Environment & setup

  • OS: tested on macOS and Debian
  • Database: PostgreSQL
  • Node.js version: 20.11.0

Prisma Version

prisma                  : 5.10.2
@prisma/client          : 5.10.2
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v20.11.0
Query Engine (Node-API) : libquery-engine 5a9203d0590c951969e85a7d07215503f4672eb9 (at ../../node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli 5a9203d0590c951969e85a7d07215503f4672eb9 (at ../../node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9
Default Engines Hash    : 5a9203d0590c951969e85a7d07215503f4672eb9
Studio                  : 0.499.0
Preview Features        : driverAdapters, metrics, views
"@prisma/adapter-pg": "^5.11.0"

Activity

  1. added
    kind/bug
    on Mar 15, 2024
  2. added
    tech/typescript
    status/is-preview-feature
    and removed
    kind/bug
    on Mar 15, 2024
  3. added
    bug/1-unconfirmed
    kind/bug
    and removed
    status/is-preview-feature
    on Mar 16, 2024
  4. changed the title [-]@prisma/adapter-pg modifies node-postgres global type parsers[/-] [+]`@prisma/adapter-pg` modifies node-postgres global type parsers[/+] on Mar 16, 2024
  5. added
    bug/2-confirmed
    and removed
    bug/1-unconfirmed
    on Apr 29, 2024
  6. jkomyno commented on Apr 29, 2024

    @jkomyno
    Contributor

    Hi @matteosb, this is indeed a current side-effect of using setTypeParser in here, as you found out. Thanks for pointing us to https://node-postgres.com/features/queries#types, we'll look into it.

    Also, thank you for mentioning the reasons you're using Prisma + lots of plain node-postgres, as this allows us to understand your use case better :)

  7. self-assigned this
    on May 17, 2024
  8. removed their assignment
    on May 30, 2024
  9. Jolg42 commented on May 30, 2024

    @Jolg42
    Contributor

    Note: assigning myself, if someone wants to take it, go for it. Happy to pair or to pick it back another day.

  10. self-assigned this
    on Jun 4, 2024
  11. added this to the 5.16.0 milestone on Jun 5, 2024
  12. self-assigned this
    on Jun 6, 2024
  13. Jolg42 commented on Jun 10, 2024

    @Jolg42
    Contributor

    @matteosb You can now try the dev version 5.16.0-dev.18

    This fix will be part of the official 5.16.0 release scheduled for June 25th ✅

  14. matteosb commented on Jun 10, 2024

    @matteosb
    Author

    Amazing thank you @Jolg42! I'm not sure that I will have time to test before June 25th but I'll try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug/2-confirmedkind/bugtech/typescripttopic: @prisma/adapter-pgtopic: driverAdapters

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions