IntegrityError when saving shop settings on Python 2.5

Issue #1013 resolved
Mikko Ohtamaa created an issue

The current trunk of Satchmo cannot save shop settings on Py2.5. IntegrityError is raised after the initial save.

The culprint is localsettings/models.py. Local settings are JSON'ied to the database. A special logic is used to check whether to perform INSERT of UPDATE.

On Python 2.5, this logic fails. Looks like Py2.6 internal JSON library behaves differently than the choice Django gives for Py2.5.

In very detail the settings are compared to see whether they exist and UPDATE should be performed. This comparison fails on Py2.5 because

  • read serialized lists are ("Visa", "Mastercard") when read but ["Visa", "Mastercard"] when written

  • Strings are UTF-8 when written but Unicode when read

Thus, comparison JSON'fied values fails on Python 2.5, it always tries to perform INSERT which causes IntegrityError.

(I am not sure if it was other way around)

Workaround: Use Python 2.6.

Comments (9)

  1. Chris Moffitt repo owner

    Can you confirm you are using the tip from bitbucket? The app is called livesettings now so I'm not sure this still applies or not.

  2. Mikko Ohtamaa reporter

    Sorry I meant livesettings, not localsettings.

    I checked out yesterday, so it is kind of fresh.

  3. Chris Moffitt repo owner

    If you remove the try: except: block in lines 9-12 of livesttings/values so that you always import simplejson from django.utils does it work?

    This workaround was put in place for Redhat because they packaged Django uniquely. We may need to back this out.

  4. Mikko Ohtamaa reporter

    Unfortunately I already scraped Python 2.5 environment in the favour of moving to Python 2.6. I am not sure when I'll be have again a working Python 2.5 + Satchmo with all its dependencies build up. But let's see if I could restore it.

  5. Mikko Ohtamaa reporter

    No dice.

    Downgraded to Python 2.5, still the same error.

    Downgraded simplejson to 1.9 so it should be identical with Py 2.6 and still the same error.

    I also poked django.utils.simplejson to force it load Django's bundled json or system JSON and both fail on Python 2.5.

    So there must be something else involved.

  6. Chris Moffitt repo owner

    I'm wondering if we should try a different format besides json. Maybe the python serializer. Since we're storing simple data structures that might work. What do you think?

  7. Former user Account Deleted

    Unless you plan to make Satchmo to work with PHP/Java, pickle is your friend. It is not human readable as JSON, but it has proven itself to be Python compatible almost 20 years now :)

    It might be also faster.

    Also one trick might be force to use certain JSON dependency which is guaranteed to work (bundle Satchmo with JSON lib). Because the behavior regarding lists and unicode seems not to be standardized among decoders.

  8. Hynek Cernoch

    Similar issued in livesettings has been fixed in order to correct romparing whether a value equals its default value. So serializers are now problem now.

    This is related livesettings issues where are Livesettings issues good analyzed now, IMO.

    For Integrity errors and similar issues is an important circumstance for reproducing one of:

    • using locmem cache in multiprocess deployment instead of memcached
    • switching between different projects experimentally without resetting memcached between
    • running multiple sites with different databases but the same SITE_ID and the same memcached.

    If you disagree, reopen this or write something to livesettings issues.

  9. Log in to comment