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

Prisma errors after being called with empty list #972

Open
sleepylemur opened this issue Jun 18, 2024 · 2 comments
Open

Prisma errors after being called with empty list #972

sleepylemur opened this issue Jun 18, 2024 · 2 comments
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.

Comments

@sleepylemur
Copy link

sleepylemur commented Jun 18, 2024

Bug description

When passing an empty list to a query that coerces it to timestamps,
a subsequent call with a non empty list causes the db to throw an exception.

Throws ERROR: improper binary format in array element 1:

await client.query_raw("select $1::timestamp[]", [])
await client.query_raw("select $1::timestamp[]", ["2024-06-17T21:34:42"])

If the list is always non-empty or the list is always empty, everything works fine.

Works fine:

await client.query_raw("select $1::timestamp[]", [])
await client.query_raw("select $1::timestamp[]", [])

Also works fine:

await client.query_raw("select $1::timestamp[]", ["2024-05-17T21:34:42"])
await client.query_raw("select $1::timestamp[]", ["2024-06-17T21:34:42"])

This wasn't terribly hard to work around once we understood what was happening,
but took a bit of effort to debug because of the surprising behavior.

How to reproduce

Run example.py with a postgresql database:

DATABASE_URL="postgresql://[email protected]:5432/postgres" python -m example

example.py

import asyncio
from prisma import Prisma

async def main():
    client = Prisma()
    await client.connect()
    print(await client.query_raw("select $1::timestamp[]", []))
    print(await client.query_raw("select $1::timestamp[]", ["2024-06-17T21:34:42"]))
    await client.disconnect()

asyncio.run(main())

Expected behavior

Prisma/PostgreSQL throws

prisma.errors.RawQueryError: ERROR: improper binary format in array element 1

Prisma information

Not relevant

Environment & setup

  • OS: Mac OS 14.5
  • Database: PostgreSQL 15
  • Python version: 3.10
  • Prisma version: 0.13.1
prisma                : 5.11.0
@prisma/client        : Not found
Computed binaryTarget : darwin-arm64
Operating System      : darwin
Architecture          : arm64
Node.js               : v20.10.0
Query Engine (Binary) : query-engine efd2449663b3d73d637ea1fd226bafbcf45b3102 (at ../../../.cache/prisma-python/binaries/5.11.0/efd2449663b3d73d637ea1fd226bafbcf45b3102/node_modules/@prisma/engines/query-engine-darwin-arm64)
Schema Engine         : schema-engine-cli efd2449663b3d73d637ea1fd226bafbcf45b3102 (at ../../../.cache/prisma-python/binaries/5.11.0/efd2449663b3d73d637ea1fd226bafbcf45b3102/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm           : @prisma/prisma-schema-wasm 5.11.0-15.efd2449663b3d73d637ea1fd226bafbcf45b3102
Default Engines Hash  : efd2449663b3d73d637ea1fd226bafbcf45b3102
Studio                : 0.499.0
@RobertCraigie
Copy link
Owner

RobertCraigie commented Jul 21, 2024

Thanks for the detailed bug report, I can reproduce the error. I've also verified that this doesn't happen in the JS client.

@RobertCraigie RobertCraigie added bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. labels Jul 21, 2024
@sleepylemur
Copy link
Author

Thanks for investigating. Again, low priority on our end due to there being an easy workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

2 participants