Changeset 206

Show
Ignore:
Timestamp:
09/24/07 00:07:13 (6 years ago)
Author:
bbangert
Message:

- Fixed bug in versioning that could cause repeat inserts of duplicates into

the version history. This was due to SA flagging items for update when they
weren't actually going to be updated.

Location:
elixir/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/CHANGES

    r205 r206  
    110.4.0 
     2- Fixed bug in versioning that could cause repeat inserts of duplicates into 
     3  the version history. This was due to SA flagging items for update when they 
     4  weren't actually going to be updated. 
    25- Implemented ondelete/onupdate options for use with has_and_belongs_to_many 
    36  to apply on delete clauses to foreign key constraints on the m2m table. 
  • elixir/trunk/elixir/ext/versioned.py

    r202 r206  
    7979        instance.version = 1 
    8080        instance.timestamp = datetime.now() 
     81        colvalues = dict([(key, getattr(instance, key)) for key in instance.c.keys()]) 
     82        instance.__class__.__history_table__.insert().execute(colvalues) 
    8183        return EXT_PASS 
    8284     
    8385    def before_update(self, mapper, connection, instance):         
    84         values = instance.table.select(get_entity_where(instance)).execute().fetchone() 
    85         colvalues = dict(values.items()) 
     86        # In SQLAlchemy 0.3.X, and possibly 0.4 (unknown), objects can  
     87        # sometimes be implicated to be saved when in fact they haven't been 
     88        # updated. If we've already inserted this version, we don't need to 
     89        # insert it again. 
     90        values = instance.__class__.__history_table__.select(get_entity_where(instance),  
     91                                       order_by=[desc(instance.c.timestamp)]).execute().fetchone() 
     92        if values and instance.version == values['version']: 
     93          return EXT_PASS 
     94         
     95        colvalues = dict([(key, getattr(instance, key)) for key in instance.c.keys()]) 
     96         
    8697        instance.__class__.__history_table__.insert().execute(colvalues) 
    8798        instance.version += 1 
     
    148159            # if the passed in timestamp is older than our current version's 
    149160            # time stamp, then the most recent version is our current version 
    150             if self.timestamp < dt:  
     161            if self.timestamp < dt: 
    151162                return self 
    152163