tutorial assumes format_timezone() returns only offset int, not tuple

Bug #610540 reported by rtjmay
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Dulwich
Fix Released
Low
Jelmer Vernooij

Bug Description

When the parse_timezone() function from dulwich.objects is used to generate a value for commit.commit_timezone and commit.author_timezone a Type Error is raised by format_timezone().

Traceback (most recent call last):
  File "/usr/lib/python2.6/pprint.py", line 59, in pformat
    return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(object)
  File "/usr/lib/python2.6/pprint.py", line 111, in pformat
    self._format(object, sio, 0, 0, {}, 0)
  File "/usr/lib/python2.6/pprint.py", line 129, in _format
    rep = self._repr(object, context, level - 1)
  File "/usr/lib/python2.6/pprint.py", line 223, in _repr
    self._depth, level)
  File "/usr/lib/python2.6/pprint.py", line 235, in format
    return _safe_repr(object, context, maxlevels, level)
  File "/usr/lib/python2.6/pprint.py", line 320, in _safe_repr
    rep = repr(object)
  File "/home/ryan/.virtualenvs/jam-try/lib/python2.6/site-packages/dulwich-0.6.1-py2.6.egg/dulwich/objects.py", line 460, in __repr__
    return "<%s %s>" % (self.__class__.__name__, self.id)
  File "/home/ryan/.virtualenvs/jam-try/lib/python2.6/site-packages/dulwich-0.6.1-py2.6.egg/dulwich/objects.py", line 448, in id
    return self.sha().hexdigest()
  File "/home/ryan/.virtualenvs/jam-try/lib/python2.6/site-packages/dulwich-0.6.1-py2.6.egg/dulwich/objects.py", line 440, in sha
    new_sha.update(self._header())
  File "/home/ryan/.virtualenvs/jam-try/lib/python2.6/site-packages/dulwich-0.6.1-py2.6.egg/dulwich/objects.py", line 419, in _header
    return object_header(self.type, self.raw_length())
  File "/home/ryan/.virtualenvs/jam-try/lib/python2.6/site-packages/dulwich-0.6.1-py2.6.egg/dulwich/objects.py", line 424, in raw_length
    for chunk in self.as_raw_chunks():
  File "/home/ryan/.virtualenvs/jam-try/lib/python2.6/site-packages/dulwich-0.6.1-py2.6.egg/dulwich/objects.py", line 220, in as_raw_chunks
    self._chunked_text = self._serialize()
  File "/home/ryan/.virtualenvs/jam-try/lib/python2.6/site-packages/dulwich-0.6.1-py2.6.egg/dulwich/objects.py", line 983, in _serialize
    self._author_timezone_neg_utc)))
  File "/home/ryan/.virtualenvs/jam-try/lib/python2.6/site-packages/dulwich-0.6.1-py2.6.egg/dulwich/objects.py", line 878, in format_timezone
    if offset % 60 != 0:
TypeError: unsupported operand type(s) for %: 'tuple' and 'int'

This issue can be worked around by using:

commit.commit_timezone = commit.author_timezone = parse_timezone('-0600')[0]

which returns the integer expected by format_timezone()

Tags: tutorial
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

This is intended behaviour, the parse_timezone function is used internally by dulwich to parse timezone fragments and it returns a tuple with a timezone and a boolean indicating whether the timezone parsed was UTC but prefixed with a negative sign ("-").

I've added docstrings to format_timezone and parse_timezone.

Revision history for this message
rtjmay (rtjmay) wrote :

The tutorial will also have to be updated, because it uses parse_timezone() in the manner outlined above.

Revision history for this message
Jelmer Vernooij (jelmer) wrote : Re: [Bug 610540] Re: format_timezone() does not properly handle output of parse_timezone()

On Tue, 2010-07-27 at 18:33 +0000, rtjmay wrote:
> The tutorial will also have to be updated, because it uses
> parse_timezone() in the manner outlined above.
We should probably make sure the tutorial gets tested in the dulwich
testsuite.

Jelmer Vernooij (jelmer)
summary: - format_timezone() does not properly handle output of parse_timezone()
+ tutorial assumes format_timezone() returns only offset int, not tuple
Changed in dulwich:
status: New → Triaged
importance: Undecided → Low
tags: added: tutorial
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

IIRC I fixed this but I can't find the related change at the moment.

Changed in dulwich:
assignee: nobody → Jelmer Vernooij (jelmer)
milestone: none → 0.7.0
status: Triaged → Fix Committed
Jelmer Vernooij (jelmer)
Changed in dulwich:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.