Coder Social home page Coder Social logo

Comments (7)

alphavector avatar alphavector commented on June 3, 2024 2

I was able to solve this for me with the following patch

def sa_patch():
    """
    sqlalchemy patch to make aiopg.sa work correctly
    """
    import sqlalchemy
    from sqlalchemy.dialects.postgresql import base, psycopg2

    class PGDialect_psycopg2(psycopg2.PGDialect_psycopg2):
        case_sensitive = True
        description_encoding = None

    setattr(sqlalchemy.dialects.postgresql.psycopg2, 'PGCompiler_psycopg2', base.PGCompiler)
    setattr(sqlalchemy.dialects.postgresql.psycopg2, 'PGDialect_psycopg2', PGDialect_psycopg2)

And this function must be called every time before importing

sa_patch()
import aiopg.sa

from aiopg.

Pliner avatar Pliner commented on June 3, 2024 2

Hello,

In the long run, it is better to upgrade(from my point of view) to sqlalchemy native async support, which was introduced in sqlalchemy v1.4 (initially, asyncpg was the only one supported) and continued in sqlachemy v2. Currently, sqlalchemy v2 has built-in async support of asyncpg and psycopg v3.

Aiopg was vital before sqlachemy began to support async, but now it doesn't make much sense for further support.

I am happy to merge any compatibility patches with sqlalchemy v2, but there are no activities from my side to support it.

from aiopg.

Pliner avatar Pliner commented on June 3, 2024 1

Resolved by #901

from aiopg.

Havrushchyk avatar Havrushchyk commented on June 3, 2024

Still reproduced -> Ubuntu 22.04 -> sqlalchemy '2.0.3', Python 3.10.6, aiopg 1.4.0

from aiopg.

nicholasrigo93 avatar nicholasrigo93 commented on June 3, 2024

Seeing the same. Problem comes from trying to import this:

try:
    from sqlalchemy.dialects.postgresql.psycopg2 import (
        PGCompiler_psycopg2,
        PGDialect_psycopg2,
    )
except ImportError:  # pragma: no cover
    raise ImportError("aiopg.sa requires sqlalchemy")

Here: https://github.com/aio-libs/aiopg/blob/ae2617d7e50ed78f24ad7fb13833614780309596/aiopg/sa/engine.py#L10

But the PGCompiler_psycopg2 object doesn't exist anymore in this script https://github.com/sqlalchemy/sqlalchemy/blob/main/lib/sqlalchemy/dialects/postgresql/psycopg2.py

from aiopg.

sakmanal avatar sakmanal commented on June 3, 2024

Are there any news for this issue? I tried alphavector's solution and it worked but official support for sqlalchemy v2 would be much appreciated. Are there any plans for this ?

from aiopg.

Pliner avatar Pliner commented on June 3, 2024

@asvetlov #798 (comment) seems to have the same opinion on that.

from aiopg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.