1

Django sitemaps worked fine on a previous server, and work fine in my development environment, but break in production on a new server, with:

ValidationError: [u'Unknown timezone'] (traceback below). I was also getting a similar error when trying to access one of our models from admin.

Update:

The path build/bdist.linux-x86_64/egg/timezones in the traceback tipped me off that there was some weird path stuff going on. Turned out someone had copied a bunch of stuff from another server rather than doing proper pip installs. I removed some old libs, fixed a virtualenv default path, and pip installed django-timezones. All working nicely now. Leaving this in case it's helpful to anyone else.


The sitemap docs don't mention anything about timezone configuration or dependencies: https://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/

The server's timezone is correctly set to America/Los_Angeles, and I've set the same in settings.py I'm not sure what else to look at here and Google's turning up nothing.

I reference 8 models in my SiteMaps definition in urls.py but only one BlogSiteMap is causing the breakage (if I comment it out the breakage stops, but then I don't have blog posts in the sitemap. It consists of:

class BlogSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.7

    def items(self):
        return Post.objects.filter(status=2).order_by('-modified')

    def lastmod(self, obj):
        return obj.modified

The blog Post model is this (edited slightly for brevity)

class Post(models.Model):
    """Post model."""

    title           = models.CharField(_('title'), max_length=200)
    slug            = models.SlugField(_('slug'), unique_for_date='publish')
    author          = models.ForeignKey(User, blank=True, null=True)
    body            = models.TextField(_('body'))
    tease           = models.TextField(_('tease'), blank=True)
    status          = models.IntegerField(_('status'), choices=STATUS_CHOICES, default=2)
    allow_comments  = models.BooleanField(_('allow comments'), default=True)
    fp_show         = models.BooleanField('Show on homepage',default=False)
    order           = models.IntegerField(blank=True, null=True)     
    publish         = models.DateTimeField(_('publish'),default=datetime.now())
    created         = models.DateTimeField(_('created'), auto_now_add=True)
    modified        = models.DateTimeField(_('modified'), auto_now=True)
    categories      = models.ManyToManyField(Category, blank=True)  
    tags            = TagField()
    objects         = PublicManager()


    def __unicode__(self):
        return u'%s' % self.title

    @permalink
    def get_absolute_url(self):
        return ('blog_detail', None, {
            'year': self.publish.year,
            'month': self.publish.strftime('%b').lower(),
            'day': self.publish.day,
            'slug': self.slug
        })

Using: Django 1.3 Python 2.7 RHEL 5.7

Thanks.

Traceback (most recent call last):

 File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/contrib/sitemaps/views.py", line 39, in sitemap
   urls.extend(site().get_urls(page=page, site=current_site))

 File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/contrib/sitemaps/__init__.py", line 75, in get_urls
   for item in self.paginator.page(page).object_list:

 File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/db/models/query.py", line 107, in _result_iter
   self._fill_cache()

 File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/db/models/query.py", line 772, in _fill_cache
   self._result_cache.append(self._iter.next())

 File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/db/models/query.py", line 286, in iterator
   obj = model(*row[index_start:aggregate_start])

 File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/db/models/base.py", line 297, in __init__
   setattr(self, field.attname, val)

 File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/db/models/fields/subclassing.py", line 99, in __set__
   obj.__dict__[self.field.name] = self.field.to_python(value)

 File "build/bdist.linux-x86_64/egg/timezones/fields.py", line 43, in to_python
   return coerce_timezone_value(value)

 File "build/bdist.linux-x86_64/egg/timezones/utils.py", line 34, in coerce_timezone_value
   raise ValidationError("Unknown timezone")

ValidationError: [u'Unknown timezone']
shacker
  • 14,712
  • 8
  • 89
  • 89
  • try to debug and see what the value is at the line 99 in File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/db/models/fields/subclassing.py" obj.__dict__[self.field.name] = self.field.to_python(value) – akonsu Oct 03 '11 at 21:27
  • akonsu - Could I trouble you for steps on how to do that? Would I need to alter Django source in production to do that? (since this only happens on the production server). Thanks. – shacker Oct 04 '11 at 18:30
  • here is a link with various ways to debug: http://stackoverflow.com/questions/1118183/how-to-debug-in-django-the-good-way. but I myself just modify the source, yes, and throw an exception with the variable that i want to inspect. – akonsu Oct 04 '11 at 18:36
  • Thanks akonsu - I'll read up there. Meanwhile, the path build/bdist.linux-x86_64/egg/timezones tipped me off that there was some weird path stuff going on. Turned out someone had copied a bunch of stuff from another server rather than doing proper pip installs. I removed some old libs, fixed a virtualenv defaul path, and pip installed django-timezones. All working nicely now. Thanks. – shacker Oct 04 '11 at 19:42

1 Answers1

0

See Update: section above - this turned out to be a series of conflicts arising from old installed libraries and an incorrect path in the virtualenv.

shacker
  • 14,712
  • 8
  • 89
  • 89