PickleType issuing "UPDATE" on objects ever when they do not change

Issue #560 resolved
Former user created an issue

Hi!

This is my first ticket about SQLAlchemy.

Recently I noticed that a routine I was running was way too much slow, then I turned on echo=True on my engine and I noticed it was issuing an UPDATE for every object I got from a query ever if I do not change anything on them.

This behaviour happened cause my table definition had a PickleType column. I changed it to have mutable=False and it works ok now, but if I need to change something on that column I need to reassing it to make sure it goes into db.

Ok, that's it folks.

--

Joao Paulo Farias

Comments (4)

  1. Mike Bayer repo owner

    we have a good deal of unit tests in this department and they all pass. please attach a fully reproducing test program illustrating the behavior to reopen this ticket.

  2. Former user Account Deleted
    • removed status
    • changed status to open

    I went through the same issue and I've attached a test that reproduces the problem.

    It depends on the data you store in your PickleType field... Simple data does not show up the problem but with something more complicated you get an update even if the object is not updated.

    Remi Jolin.

  3. Mike Bayer repo owner

    specifically, its the dicts/lists youre doing there. unfortunately:

    import cPickle
    
    x = [{'nom': u'Smith', 'pers_id': 1, 'prenom': u'john', 'civilite': u'Mr', \
                'int_3': False, 'int_2': False, 'int_1': u'23', 'VenSoir': True, 'str_1': u'Test', \
                'SamMidi': False, 'str_2': u'chien', 'DimMidi': False, 'SamSoir': True, 'SamAcc': False}}]({'personne':)
    y = [{'nom': u'Smith', 'pers_id': 1, 'prenom': u'john', 'civilite': u'Mr', \
                'int_3': False, 'int_2': False, 'int_1': u'23', 'VenSoir': True, 'str_1': u'Test', \
                'SamMidi': False, 'str_2': u'chien', 'DimMidi': False, 'SamSoir': True, 'SamAcc': False}}]({'personne':)
    
    print x==y
    
    print cPickle.dumps(x) == cPickle.dumps(y)
    

    returns True for x==y, but False for the latter (the latter is how PickleType compares). a workaround is to use:

      class MyEqPickle(PickleType):
          def compare_values(self, x, y):
              return x == y
    

    I don't at the moment see any generalized way to fix this problem other than providing more flags on PickleType (probably "PickleType(comparator=operator.eq)")), theres maybe some guesswork magic that could happen but im less excited about that. So i've added the comparator option in 7f6bf93da869a5b59c53d0d10a50da3c23c4b738.

  4. Log in to comment