UnknownTimezoneError / pytz quirks

Have any of you run into this type of error? I have been exporting Archetype content items from Plone 2.5 and recreating them with Dexterity on Plone 5.0.4. It happens with 'GMT-5' and 'GMT-6' when I attempt to view the folder containing these new items or when I try to view one of the new items. I had to jump through some hoops to convert DateTime values to datetime, but I thought that using DateTime's ISO8601() method would avoid some of the inconsistencies I found in the old values (some had time zones, some did not).

2017-05-21 16:13:34 ERROR ZODB.Connection Couldn't load state for 0x2c1eff
Traceback (most recent call last):
  File "/Users/kim/PloneBuilds/Plone-5.0.4-unified-clean/buildout-cache/eggs/ZODB3-3.10.5-py2.7-macosx-10.11-x86_64.egg/ZODB/Connection.py", line 860, in setstate
    self._setstate(obj)
  File "/Users/kim/PloneBuilds/Plone-5.0.4-unified-clean/buildout-cache/eggs/ZODB3-3.10.5-py2.7-macosx-10.11-x86_64.egg/ZODB/Connection.py", line 914, in _setstate
    self._reader.setGhostState(obj, p)
  File "/Users/kim/PloneBuilds/Plone-5.0.4-unified-clean/buildout-cache/eggs/ZODB3-3.10.5-py2.7-macosx-10.11-x86_64.egg/ZODB/serialize.py", line 612, in setGhostState
    state = self.getState(pickle)
  File "/Users/kim/PloneBuilds/Plone-5.0.4-unified-clean/buildout-cache/eggs/ZODB3-3.10.5-py2.7-macosx-10.11-x86_64.egg/ZODB/serialize.py", line 605, in getState
    return unpickler.load()
  File "/Users/kim/PloneBuilds/Plone-5.0.4-unified-clean/buildout-cache/eggs/pytz-2015.7-py2.7.egg/pytz/__init__.py", line 286, in _p
    return unpickler(*args)
  File "/Users/kim/PloneBuilds/Plone-5.0.4-unified-clean/buildout-cache/eggs/pytz-2015.7-py2.7.egg/pytz/tzinfo.py", line 526, in unpickler
    tz = pytz.timezone(zone)
  File "/Users/kim/PloneBuilds/Plone-5.0.4-unified-clean/buildout-cache/eggs/pytz-2015.7-py2.7.egg/pytz/__init__.py", line 180, in timezone
    raise UnknownTimeZoneError(zone)
UnknownTimeZoneError: (UnknownTimeZoneError('GMT-5',), <function _p at 0x10d1155f0>, ('GMT-5',))

For now I've been able to get around these errors by hacking buildout-cache/eggs/pytz-2015.7-py2.7.egg/pytz/tzinfo.py so that it catches the exception in unpickler() but it makes me uneasy to have to do so:

def unpickler(zone, utcoffset=None, dstoffset=None, tzname=None):
    """Factory function for unpickling pytz tzinfo instances.

    This is shared for both StaticTzInfo and DstTzInfo instances, because
    database changes could cause a zones implementation to switch between
    these two base classes and we can't break pickles on a pytz version
    upgrade.
    """
    # Raises a KeyError if zone no longer exists, which should never happen
    # and would be a bug.
    try:
        tz = pytz.timezone(zone)
    except:
        tz = pytz.timezone('America/Chicago')
        logger.warn('replacing bad timezone %s with America/Chicago' % zone)
1 Like

Here's the import code that tries to fix some problems with datetime/DateTime:

    if created and len(created):
        created = (DateTime.DateTime(created)).asdatetime()
    if modified and len(modified):
        modified = (DateTime.DateTime(modified)).asdatetime()
    if DepartureDate and len(DepartureDate):
        DepartureDate = (DateTime.DateTime(DepartureDate)).asdatetime().date()
    if ReturnDate and len(ReturnDate):
        ReturnDate = (DateTime.DateTime(ReturnDate)).asdatetime().date()
    if OrientationDate1 and len(OrientationDate1):
        OrientationDate1 = (DateTime.DateTime(OrientationDate1)).asdatetime().date()
    if OrientationDate2 and len(OrientationDate2):
        OrientationDate2 = (DateTime.DateTime(OrientationDate2)).asdatetime().date()
    if ConflictDate and len(ConflictDate):
        ConflictDate = (DateTime.DateTime(ConflictDate)).asdatetime().date()
    if CompletionDate and len(CompletionDate):
        CompletionDate = (DateTime.DateTime(CompletionDate)).asdatetime().date()

IIRC I fixed this error monkey patching pytz to rewrite the GMT+N timezones to Etc/GMT+N.

Look for the available timezones in /Users/kim/PloneBuilds/Plone-5.0.4-unified-clean/buildout-cache/eggs/pytz-2015.7-py2.7.egg/pytz/zoneinfo/.

The cited method worked for me. If I am not wrong also @gyst did something similar.

But probably the man who knows the better answer is Regebro.

1 Like

Be aware that GMT+N is not Etc/GMT+N but Etc/GMT-N.

I found this when migrating an old Plone from 3 to 5 and running some transmogrifier pipelines to create the new content.

Have a look here for more information: https://stackoverflow.com/questions/4008960/pytz-and-etc-gmt-5

If you are using transmogrifier, look to this blueprint to fix your datetime values:

2 Likes

Thank you everyone - I'm glad to find out I wasn't doing something wrong!

1 Like

Plone Foundation Code of Conduct