`composite` with in-place custom values getter · Issue #13153 · sqlalchemy/sqlalchemy · GitHub
Skip to content

composite with in-place custom values getter #13153

@Tishka17

Description

@Tishka17

Describe the use case

Currently, nested composites or custom classes require implementing __composite_values__, which is not always an option. Internally there is _generated_composite_accessor which is generated if no such method provided.

I suggest adding values_getter as an argument to composite() so it will used instead of generated accessor or method.

Databases / Backends / Drivers targeted

any

Example Use

bd = composite(
    lambda y,m,d: Birthdate(y, MyDate(m, d)),
    users_table.c.year,
    users_table.c.month,
    users_table.c.day,
    values_getter=lambda o: (o.year, o.date.month, o.date.day)
)

Additional context

Currently it is possible to hack sqlalchemy and rewrite proposed code in this way and it actually works:

bd = composite(
    lambda y,m,d: Birthdate(y, MyDate(m, d)),
    users_table.c.year,
    users_table.c.month,
    users_table.c.day,
)
bd._generated_composite_accessor = lambda o: (o.year, o.date.month, o.date.day)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ormuse casenot really a feature or a bug; can be support for new DB features or user use cases not anticipated

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions