Skip to content

Bug in linking SQLAlchemy model to dataclass when using different SQL column name and model field name #424

@ivankarmanow

Description

@ivankarmanow

OS: Windows 11 Pro 24H2
Python: 3.13.5
Adaptix: 3.0.0b11

Hello, discovered a bug in the conversion of an SQLAlchemy model to a dataclass when the model contains a field with a different name than the
corresponding column in the database. However, the reverse conversion works correctly.

Here's the MVP:

class Sql(Base):
    __tablename__ = 'Sql'

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column("user_name", key="name")

@dataclass
class Dt:
    id: int
    name: str

m2e = get_converter(Sql, Dt)
print(m2e(Sql(
    id=1,
    name="Test"
)))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions