> This works nicely for attributes that I set directly. However, it > breaks when it comes across a column that is defined as: > > sa.Column('date_created', sa.DateTime, > default=sa.func.current_timestamp(type=sa.DateTime)) > > The attached script should show the problem. The traceback is: > > Traceback (most recent call last): > File "satest.py", line 32, in after_insert > print " %s = %r" % (prop.key, getattr(instance, prop.key)) > File > "/home/warranty/python/development/lib/python2.5/site-packages/SQLA >lchem y-0.4.1-py2.5.egg/sqlalchemy/orm/attributes.py", line 40, in > __get__ return self.impl.get(obj._state) > File > "/home/warranty/python/development/lib/python2.5/site-packages/SQLA >lchem y-0.4.1-py2.5.egg/sqlalchemy/orm/attributes.py", line 215, in > get value = callable_() > File > "/home/warranty/python/development/lib/python2.5/site-packages/SQLA >lchem y-0.4.1-py2.5.egg/sqlalchemy/orm/attributes.py", line 628, in > __fire_trigger > self.trigger(instance, [k for k in self.expired_attributes if k > not in self.dict]) > File > "/home/warranty/python/development/lib/python2.5/site-packages/SQLA >lchem y-0.4.1-py2.5.egg/sqlalchemy/orm/session.py", line 1112, in > load_attributes > if > object_session(instance).query(instance.__class__)._get(instance._i >nstan ce_key, refresh_instance=instance, > only_load_props=attribute_names) is None: > AttributeError: 'User' object has no attribute '_instance_key' > > I assume the problem is that my date_created column isn't > immediately available at the 'after_insert' stage, because it is > generated in the SQL INSERT statement, but hasn't been read back > from the database yet. Is there a more suitable hook-point than > after_insert, where I can safely read values like this? > i was going to suggest u to do a session.expire( that_attribute) but as i see from the traceback it is going after expired attrs and failing there, so thats for Michael... eventualy the after_insert is happening too early and the _instance_key etc SA-system stuff is not set on the object yet.
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---