> > However, I have issues with the difference in NULL value semantics
> > between Python and SQL. Ie. if a calculated column is defined via a
> > column_property as price*amount, then the result will be NULL if any
> > of the values is NULL. However, in Python, None*something throws a
> > TypeError, so the hybrid_property getter function needs to be filled
> > with lots of IFs.
>
> When called as class properties, the descriptors always generate
> SQL expressions as above.
>
> When called as instance properties, it just calls your function and
> you can
> do what you like with None values, e.g.:
>
> @hybrid_property
> def length(self):
>     return self.thing is not None and self.thing or None

That's what I did, I just wasn't sure it's the right way to do it.

> > Also, this solution can't be used for date calculations, as timedelta
> > objects are needed. So I guess I will stick with a mix of Python
>
> The example works in postgresql with timestamps and intervals/
> timedeltas. ;-)
>
> a.

Then I'm doing something terribly wrong. If I define:
due_date = hybrid_property(lambda self: self.invoce_date +
self.payment_days)

When querying with session.query(Invoice).filter
(Invoice.due_date<date.today()).all(), I get the following error:
TypeError: unsupported type for timedelta days component:
InstrumentedAttribute

This is with PostgreSQL and SQLAlchemy 0.5.8.
-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to