@@ -0,0 +1,1789 @@
+'''%0AFix an error in the previous migration where wie pickled the versions%0Ainto a string that was pickled again by sqlalchemy.%0A'''%0Afrom datetime import datetime%0Afrom pickle import loads%0A%0Afrom sqlalchemy import (MetaData, Column, ForeignKey, DateTime, Integer,%0A                        PickleType, Table)%0A%0Ametadata = MetaData()%0A%0A%0Adef are_elements_equal(x, y):%0A    return x == y%0A%0A%0Aselection_table = Table(%0A    'selection', metadata,%0A    Column('id', Integer, primary_key=True),%0A    Column('create_time', DateTime, default=datetime.utcnow),%0A    Column('delete_time', DateTime),%0A    Column('page_id', Integer, ForeignKey('page.id',%0A           name='selection_page', use_alter=True), nullable=True),%0A    Column('proposal_id', Integer, ForeignKey('proposal.id',%0A           name='selection_proposal', use_alter=True), nullable=True),%0A    Column('variants', PickleType(comparator=are_elements_equal),%0A           nullable=True)%0A    )%0A%0A%0Adef upgrade(migrate_engine):%0A%0A    metadata.bind = migrate_engine%0A%0A    selections = migrate_engine.execute(selection_table.select())%0A    fixed = 0%0A    for (id, _, _, _, _, variants) in selections:%0A        try:%0A            # see if we can unpickle from the variants value%0A            variants = loads(variants)%0A        except TypeError:%0A            continue%0A%0A        if not isinstance(variants, list):%0A            raise ValueError(%0A                (%22Already fixed: %25s. Error in selection %25s. 'variants' is %22%0A                 'double pickled, but not a list. Value: %25s, type: %25s') %25%0A                (id, str(variants), type(variants)))%0A        fixed += 1%0A        migrate_engine.execute(%0A            selection_table.update().values(variants=variants).where(%0A                selection_table.c.id == id))%0A%0A%0Adef downgrade(migrate_engine):%0A    raise NotImplementedError()%0A

Add migration for double pickled values