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

add support for @property and @hybrid_property

Open finswimmer opened this issue 4 years ago • 3 comments

This PR adds support for attributes defined by @property or @hybrid_property. The corresponding functions must provide a type hint for the return type.

I'm not sure if I identify hybrid_properties the right way, or if the check is to broad.

finswimmer avatar Feb 03 '21 18:02 finswimmer

Codecov Report

Merging #26 (b7b9608) into master (8667e21) will not change coverage. The diff coverage is 100.00%.

:exclamation: Current head b7b9608 differs from pull request most recent head 7583638. Consider uploading reports for the commit 7583638 to get more accurate results Impacted file tree graph

@@            Coverage Diff            @@
##            master       #26   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         3    +1     
  Lines          127       215   +88     
=========================================
+ Hits           127       215   +88     
Impacted Files Coverage Δ
pydantic_sqlalchemy/main.py 100.00% <100.00%> (ø)
tests/conftest.py 100.00% <100.00%> (ø)
tests/test_pydantic_sqlalchemy.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8667e21...7583638. Read the comment docs.

codecov[bot] avatar Feb 03 '21 18:02 codecov[bot]

Hm, I see no chance to get the test coverage to 100% when having if TYPE_CHECKING: in the code :cry:

finswimmer avatar Feb 04 '21 05:02 finswimmer

You can get hybrid attributes with the hybrid_attributes property: db_model.hybrid_attributes. Maybe just merge both, mapper.attributes and db_model.hybrid_attributes when doing the for loop works out?

nico525 avatar Feb 07 '21 19:02 nico525

Thank you for all the work you put here @finswimmer! :nerd_face:

Thanks for the patience with my reply. :sweat_smile:

I deprecated this library a while ago in favor of SQLModel which would solve all the same use cases in a much better way, and I'm directing all the effort in that direction, so sadly I wouldn't be able to take new features here (that would also need maintaining them).

Given that, I'll close this one, but thanks for the effort! :coffee:

tiangolo avatar Sep 08 '24 12:09 tiangolo