Skip to content

Error while searching by multiple columns of joined model #901

@pokidovea-playrix

Description

@pokidovea-playrix

Checklist

  • The bug is reproducible against the latest release or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

There's an SQL error while searching by multiple columns of joined model

Steps to reproduce the bug

class Table1(Base):
    __tablename__ = 'table1'
    
    id: Mapped[int] = mapped_column(primary_key=True)
    field1: Mapped[str] = mapped_column(String, nullable=False)


class Table2(Base):
    __tablename__ = 'table2'
    
    id: Mapped[int] = mapped_column(primary_key=True)
    field2: Mapped[str] = mapped_column(String, nullable=False)

    table1_id = Mapped[int] = mapped_column(ForeignKey('table1.id'), index=True, nullable=False)

    table1: Mapped['Table1'] = relationship()


class Table3(Base):
    __tablename__ = 'table3'

    id: Mapped[int] = mapped_column(primary_key=True)
    table2_id = Mapped[int] = mapped_column(ForeignKey('table2.id'), index=True, nullable=False)

    table2: Mapped['Table2'] = relationship()


class Table3AdminView(ModelView, model=Table3):
    column_searchable_list = ['table2.table1.field1', 'table2.field2']

Expected behavior

No response

Actual behavior

Error

 sqlalchemy.exc.ProgrammingError: (sqlalchemy.dialects.postgresql.asyncpg.ProgrammingError) <class 'asyncpg.exceptions.DuplicateAliasError'>: table name "table2" specified more than once

Debugging material

No response

Environment

  • python 3.12
  • sqladmin = {version = "^0.20.1", extras = ["full"]}

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions