sqlalchemy-history icon indicating copy to clipboard operation
sqlalchemy-history copied to clipboard

Fix builder not copying hybrid_property.expr and other props to the version class

Open maximvlah opened this issue 9 months ago • 1 comments

Found and fixed the bug in Builder.create_hybrid_properties. It was only copying the python hybrid property function to the corresponding version class but not the SQL equivalent, thus we would get the error below:

self = <class 'sqlalchemy_history.model_builder.ArticleVersion'>

    @sa.ext.hybrid.hybrid_property
    def author_name(self):
>       return self.author.name
E       AttributeError: 'property' object has no attribute 'name'

tests/test_hybrid_property.py:37: AttributeError
================================================================================================= short test summary info ==================================================================================================
FAILED tests/test_hybrid_property.py::TestHybridProperty::test_version_class_hybrid_property_in_sql_expression - AttributeError: 'property' object has no attribute 'name'

maximvlah avatar Mar 28 '25 17:03 maximvlah

Thanks for fixing it, we ran into problems here as well!

@aditya051293 Would you mind having a look?

abulvenz avatar Mar 31 '25 07:03 abulvenz