I wanted to follow up on this thread.

Mike’s suggestion above 
<https://groups.google.com/g/sqlalchemy/c/nHz9z_P15qg/m/HWk8g8gGCAAJ> 
worked, and considering the related discussion Dataclasses and Composites 
with init-only variables 
<https://github.com/sqlalchemy/sqlalchemy/discussions/10988> I adjusted the 
code somewhat: instead of using the *nullable_point()* function (from 
above) I extended the *as_composite()* class method (from the other thread) 
as suggested:

*@classmethod*
*def as_composite(cls, x: int | None, y: int | None) -> Point | None:*
*    if x is None and y is None:*
*        return None*
*    return Point(x, y)*

Then adjust the mapper types accordingly, and that’s it 👍🏼

Thanks!
Jens

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/2e52030a-8772-4876-8c74-1f607d2af049n%40googlegroups.com.

Reply via email to