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

AttributeError: 'CrateCompilerSA20' object has no attribute 'visit_on_conflict_do_update' #186

Open
amotl opened this issue Dec 13, 2024 · 1 comment

Comments

@amotl
Copy link
Member

amotl commented Dec 13, 2024

Problem

When deriving a CrateDB adapter for LangChain from langchain-postgres, we are observing this error when invoking a test case.

pytest -vvv -k test_add_documents_documents
    def _compiler_dispatch(
        self: Visitable, visitor: Any, **kw: Any
    ) -> str:
        """Look for an attribute named "visit_<visit_name>" on the
        visitor, and call it with the same kw params.

        """
        try:
>           meth = getter(visitor)
E           AttributeError: 'CrateCompilerSA20' object has no attribute 'visit_on_conflict_do_update'
@amotl amotl changed the title AttributeError: 'CrateCompilerSA20' object has no attribute 'visit_on_conflict_do_update' AttributeError: 'CrateCompilerSA20' object has no attribute 'visit_on_conflict_do_update' Dec 13, 2024
@amotl
Copy link
Member Author

amotl commented Dec 14, 2024

Can quickly be solved using a monkeypatch. Needs to be upstreamed to sqlalchemy-cratedb.

def patch_sqlalchemy_dialect():
    """
    Fixes `AttributeError: 'CrateCompilerSA20' object has no attribute 'visit_on_conflict_do_update'`

    TODO: Upstream to `sqlalchemy-cratedb`.
          https://github.com/crate/sqlalchemy-cratedb/issues/186
    """  # noqa: E501
    from sqlalchemy.dialects.postgresql.base import PGCompiler
    from sqlalchemy_cratedb.compiler import CrateCompiler

    CrateCompiler.visit_on_conflict_do_update = PGCompiler.visit_on_conflict_do_update
    CrateCompiler._on_conflict_target = PGCompiler._on_conflict_target


patch_sqlalchemy_dialect()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant