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)
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_accessorwhich is generated if no such method provided.I suggest adding
values_getteras an argument tocomposite()so it will used instead of generated accessor or method.Databases / Backends / Drivers targeted
any
Example Use
Additional context
Currently it is possible to hack sqlalchemy and rewrite proposed code in this way and it actually works: