On Jul 28, 2014, at 1:33 PM, Jonathan Vanasco <[email protected]> wrote:
> I just encountered an Exception because SqlAlchemy didn't work the way I > expected it to. (It did work as per a section in the docs, which I obviously > didn't read carefully enough). > > Actual Behavior: A default value in the ORM applies as a 'backup' for INSERT > and UPDATES > (wrongfully) Expected Behavior: A default value in the ORM assigns the value > on __init__ > > Has anyone figured out a good way to use the ORM defaults as an object > __init__ default ? > > There are a handful of Q&As on this over at StackOverflow, but the answers > are all over the place, and I'm not particularly impressed with them. SQLAlchemy should probably have a better story for this at some point, but you can intercept the init() event and within there, iterate through mapper.column_attrs, look into the defaults that are applicable and apply. it's hard to generalize because some defaults are SQL functions, some are Python functions that require context in order to work. -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
