Skip to content

Seemingly random occurences of error "module 'psycopg2' has no attribute 'extensions'" #550

@martijnarts

Description

@martijnarts

Hello,

I'm trying to get some better insight into why this error is occurring on our systems. I've googled the error and couldn't find anything else, so here I am.

For a situation sketch: we're installing psycopg2 as a dependency of SQLAlchemy, through Pip, on a Python3.6 installation, in Alpine Linux, on Docker (image python:3.6-alpine—see the illustrative Docker file). Seemingly at random times, we get an AttributeError: module 'psycopg2' has no attribute 'extensions' (also see partial stack trace below). I've been trying to figure out what causes this error, but I haven't been able to reproduce it or pinpoint really anything that could lead to reproduction about it.

Currently, my hunch is that it occurs for every run of a certain Docker build, but that it's still random at build time. I am still in the process of confirming that suspicion though.

I will continue my research of course, and report back. I've opened this issue hoping that maybe someone has an idea of how to reproduce this, or some pointers, or a fix even.


Main exception

Traceback (most recent call last):
…
  File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/__init__.py", line 387, in create_engine
    return strategy.create(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py", line 80, in create
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "/usr/local/lib/python3.6/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 554, in dbapi
    import psycopg2
  File "/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py", line 67, in <module>
    import psycopg2.extensions as _ext
AttributeError: module 'psycopg2' has no attribute 'extensions'

Dockerfile (illustrative, not tested/reproducing)

FROM python:3.6-alpine

RUN apk add --no-cache \
    postgresql \
    postgresql-dev \
    python3-dev \

COPY requirements.txt .
RUN pip install -r requirements.txt

CMD …

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions