Neo4J python driver doesn't raise errors when ruuning into a docker container

164 views Asked by At

I have a problem that is probably quite simple, but I can't find solutions by myself...

I run two docker containers with docker-compose, one is a python server with fastapi, and another one the neo4j official image, with auth disabled (for dev environment) Here the piece of code that connect the db:

    def __new__(cls, settings: Neo4jSettings, *args, **kwargs):
        try:
            cls.driver = GraphDatabase.driver(settings.neo4j_url())
            log.info(f'Connected as "{settings.neo4j_user}" on {settings.neo4j_url()}')

        except exceptions.ServiceUnavailable as err:
            log.error(f'Service Unavailable: {err}')
        # other error handling

ON MY LOCAL MACHINE: everything work as expected: when the database is running, i see the connected ... message, and all is working fine. when i shutdown the database, the neo4j diver raise a Service Unavailable, and i display the error.

ON DOCKER: All works as expected when the two containers are running, with the proper database url. BUT if i change the url to a random one, or even if i shutdown the database container, the connected ... message is displayed. Look like the neo4j driver don't raise any exception ... but and can't find a reason for that.

Here my Dockerfile:

FROM python:3.7-slim # tried with 3.9 too  

WORKDIR /app


ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

COPY requirements.txt .

RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["uvicorn", "main:api", "--reload" ,"--host", "0.0.0.0", "--port", "8000"]

Thanks you, and forgive me for my english ...

0

There are 0 answers