On Aug 24, 2010, at 11:03 AM, Frank wrote: > Hello, > > I am trying to reflect the example from > http://hg.sqlalchemy.org/sqlalchemy/file/04c17c7d88d6/examples/association/basic_association.py > but with my own data structures. > > I want to manage nutrients, nutrient values and nutrition lists. > Therefore I have created a custom data type "weight" which helps me > doing calculations with weights in different units. The relation > between nutrients and nutrition lists is m:n, one list can have many > nutrients and nutrients can be in many lists. The association table > (nutrition values) stores the amount of a nutrient associated to one > list. I think I got things working mostly, but flushing my data to the > database breaks the program: > http://paste.pocoo.org/show/253961/ > > From what I understand from the message, there seems to be a problem > with my custom data type. Maybe someone with more skill in sqlalchemy > than me can shed some light on the matter ... > > Here's the full script > > http://paste.pocoo.org/show/253956/
the TypeDecorator just needs to handle the case where the bind or result value is None: class WeightType(types.TypeDecorator): impl = types.Numeric def process_bind_param(self, weight, dialect): if weight is None: return None return weight.base_value def process_result_value(self, value, dialect): if value is None: return None return Weight(value, "g") script runs fine after that. You probably meant to name the "nutrient_weight" column as "weight", or otherwise remap the attribute on the NutritionValue class mapper with that name. > > Many thanks > > Frank > > -- > 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. > -- 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.