prisma-client-py
prisma-client-py copied to clipboard
BinaryNotFoundError When Running in Docker
Bug description
I'm trying to use Python Prisma in Docker container, but when I try to initialize Prisma()
I get a BinaryNotFoundError
. It prompts me to run prisma py fetch
to solve this, but that doesn't seem to download the binary correctly either.
How to reproduce
Using this Dockerfile:
FROM python:3.11
WORKDIR /app
RUN pip install pipenv
RUN pip install --no-cache-dir -U prisma
COPY ./prisma/schema.prisma ./
RUN python -m prisma generate
# This is currently not solving the problem...
RUN python -m prisma py fetch
COPY ./python ./python
COPY ./python/Pipfile ./python/Pipfile.lock ./
RUN pipenv install --deploy --ignore-pipfile
ENV AUTONOMOUS_ROOT = "/app"
ENV PYTHONPATH "${PYTHONPATH}:/app/python"
ENV PATH="/home/prisma/.local/bin:${PATH}"
# It's possible we may need to set this manually.
# ENV PRISMA_QUERY_ENGINE_BINARY=...
CMD ["pipenv", "run", "python", "/app/python/scripts/test_prisma.py"]
... and this schema.prisma
...
generator tsClient {
provider = "prisma-client-js"
output = ".././node_modules/.prisma/client"
binaryTargets = ["debian-openssl-1.1.x"]
}
generator pythonClient {
provider = "prisma-client-py"
recursive_type_depth = 5
interface = "sync"
output = ".././python/prisma"
}
... the Docker Image builds successfully, I get this traceback when I run the container:
Traceback (most recent call last):
File "/app/python/scripts/test_prisma.py", line 22, in <module>
asyncio.run(main())
File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/app/python/scripts/test_prisma.py", line 11, in main
await prisma.connect()
^^^^^^^^^^^^^^^^
File "/app/python/prisma/client.py", line 301, in connect
self.__engine.connect(
File "/app/python/prisma/engine/query.py", line 135, in connect
self.file = file = self._ensure_file()
^^^^^^^^^^^^^^^^^^^
File "/app/python/prisma/engine/query.py", line 123, in _ensure_file
return utils.ensure(BINARY_PATHS.query_engine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/python/prisma/engine/utils.py", line 117, in ensure
raise errors.BinaryNotFoundError(
prisma.engine.errors.BinaryNotFoundError: Expected /app/prisma-query-engine-debian-openssl-3.0.x, /root/.cache/prisma-python/binaries/5.4.2/ac9d7041ed77bcc8a8dbd2ab6616b39013829574/prisma-query-engine-debian-openssl-3.0.x or /Users/mdavish/autonomous-commerce/node_modules/prisma/query-engine-darwin-arm64 to exist but none were found or could not be executed.
Try running prisma py fetch
However, even adding prisma py fetch
to the Dockerfile doesn't solve the problem.
Expected behavior
I am expecting the Prisma binary to be installed under /root/.cache/prisma-python/binaries/5.4.2/ac9d7041ed77bcc8a8dbd2ab6616b39013829574/prisma-query-engine-debian-openssl-3.0.x
but when I go into the container's shell, I'm not able to find it at that path, and running prisma py fetch
does not seem to put it there.
Prisma information
See above for Prisma schema
Environment & setup
- All of the above works on my local machine (Mac OS), but not in Docker
- Postgres database
- Prisma version 5.4.2
- Prisma Client Python version 0.11
- Python 3.11
Set the PATH
ENV
to look at /root/.local/bin/:${PATH}
instead of /home/prisma/.local/bin:${PATH}
shall work.
Hey thanks @abbazs but sadly that didn't work either. Still getting the same error. Any other ideas? Do you have any examples of a working Docker image?
set this environment variable before run prisma generate
RUN PRISMA_BINARY_CACHE_DIR=/.binaries prisma generate
Hey @mdavish, could you find any solution? I have the same issue. I also tried this:
RUN PRISMA_BINARY_CACHE_DIR=/.binaries prisma generate
It seems to me that it generally does not load the binary target regardless of the specified binary path. Can it be possible to generate the missing query engine with "prisma-client-js" as provider?
Facing the same issue. Could anyone find a solution to this?