bmuller / twistar

Twistar is an object-relational mapper (ORM) for Python that uses the Twisted library to provide asynchronous DB interaction.
http://findingscience.com/twistar
Other
132 stars 38 forks source link

toHash and Decimal #58

Closed morfair closed 9 years ago

morfair commented 9 years ago

.toHash() function return PostgreSQL numeric() type as Decimal, AutobahnPython can't JSON serialize it.

.toHash() result: { 'longitude': Decimal('41.036283') }

Autobahn error: wamp.error.invalid_payload WAMP serialization error (Decimal('41.036283') is not JSON serializable)

bmuller commented 9 years ago

.toHash is guaranteed to return a dictionary, but whether or not it's JSON serializable is not a concern of this library (in fact, there is absolutely no use of json whatsoever in the library). If you'd like to be able to JSON serialize the result, then you should just extend json.JSONEncoder (as described here) so that it can handle the Decimal type.