It would be useful for me, but I am not sure how many others.  I am
not confident enough to write a patch for it yet though.

I could not get the above to work, that may be my bug, as I use
mappers a bit too ruthlessly over my tests they (or I) get a bit
confused.
It fails less though if I run compile_mappers() and even less if I run
mapper.compile() before I run the above but I always hit an
UnmappedClassError at some point, for a class which, to me, seems
mapped (I run the above just after its been mapped and run compile).
The class, table and mapper are wrapped in another class instance,
which may be the issue, but the actual reason currently mystifies me.

At the moment I am just using an unmodified AttributeExtension on each
column I want to get active_history for.  Which was not a pain for me
and looking at the AttributeImpl code, incurs little overhead.





On Feb 24, 2:46 am, Michael Bayer <mike...@zzzcomputing.com> wrote:
> ive thought about this and it might be the kind of thing we just add a  
> flag on mapper() for.    I had exactly this same issue with a project  
> I did for someone.  The solution I gave below works, but needs to be  
> called only after compile_mappers() is called.
>
> On Feb 23, 2009, at 5:16 PM, Michael Bayer wrote:
>
>
>
> > there is not, you'd have to do something along the lines of:
>
> >   for prop in local_mapper.iterate_properties:
> >         getattr(local_mapper.class_, prop.key).impl.active_history =
> > True
>
> > On Feb 23, 2009, at 4:18 PM, kindly wrote:
>
> >> This did not end up working as, I think, active_history is by default
> >> false.  Is there a way in a mapper to set this for all attributes to
> >> be True?  Its a shame as any AttributeExtension will fix this as they
> >> imply True.
>
> >> On Feb 18, 3:23 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> >>> get_history() is a public function within the attributes package at
> >>> the top level, and I also added API documentation for it recently
> >>> (not
> >>> on the site yet).
>
> >>> from sqlalchemy.orm.attributes import get_history, instance_state
>
> >>> get_history(instance_state(myobject), "someattribute")
>
> >>> in the latest trunk you can pass "myobject" straight to get_history
> >>> without using instance_state.
>
> >>> session.is_modified() just calls get_history() on every attribute,  
> >>> so
> >>> you might want to consider just looping through the attributes the
> >>> way
> >>> is_modfied() does and do your history operation inline.
>
> >>> On Feb 18, 2009, at 9:43 AM, kindly wrote:
>
> >>>> Hello
>
> >>>> I intend to log any changes (not new rows) to a table.
>
> >>>> The simplist way I can see to do this is to check every object
> >>>> that is
> >>>> "add"ed for changes.  I intend to, before every flush, look in
> >>>> "dirty"
> >>>> then use is_modified and if there is a change use get_history to
> >>>> find
> >>>> out the original and new attribute values.  I am wary of doing it
> >>>> this
> >>>> way as _sa_instance_state looks private even though get_history is
> >>>> not.  Should this be safe to use?  Or is there a better way?
>
> >>>> Thanks
>
> >>>> David
--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to