Skip to content

LTreeType and LTree with the new version of sqlalchemy #697

Open
@caufman

Description

@caufman

Library version 0.40.0, sqlalchemy 2.0.4
Created this model:

from sqlalchemy_utils import Ltree

class Node(Base):
    __tablename__ = 'nodes'

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[Ltree] = mapped_column(nullable=False)

As a result of running the code I have these errors:

sqlalchemy.exc.ArgumentError: Could not locate SQLAlchemy Core type for Python type <class 'sqlalchemy_utils.primitives.ltree.Ltree'> inside the 'name' attribute Mapped annotation

sqlalchemy.exc.ArgumentError: The type provided inside the 'name' attribute Mapped annotation is the SQLAlchemy type <class 'sqlalchemy_utils.types.ltree.LtreeType'>. Expected a Python type instead

How to use LTreeType and LTree types correctly with the new version of sqlalchemy? It looks like the documentation hasn't been updated yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions