Your message dated Mon, 5 Sep 2016 11:19:23 +0100
with message-id <[email protected]>
and subject line txtorcon: Should age() use an old new timestamp?
has caused the Debian Bug report #833821,
regarding txtorcon: Should age() use an old new timestamp?
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
833821: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833821
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: txtorcon
Version: 0.15.0-1
Tags: patch

I noticed this issue because the package fail to build reproducably, and
sphinx generate documentation where the now statement below is replaced
with a concrete timestamp.  See <URL: > for the details about this.

But while looking at the code, it occured to me that it probably is not
working as the author intended.  If I remember correctly (based on a
blog post from Chris Lamb[1]), the default function arguments in Python
are evaluated when the code is parsed (ie when the 'import' statements
are evaluated).  The effect of this is that the age() function is not
give a fresh new timestamp generated at call time, but the timestamp
generated when the file was imported.

 [1] <URL: 
https://chris-lamb.co.uk/posts/python-quirk-signatures-are-evaluated-import-time
 >

I suspect the author wanted fresh timestamp, and suggest to rewrite the
age() function like this to make sure age() without any now value
specified actually uses a fresh timestamp:

diff --git a/txtorcon/circuit.py b/txtorcon/circuit.py
index 5166fc1..cd9a3cf 100644
--- a/txtorcon/circuit.py
+++ b/txtorcon/circuit.py
@@ -157,7 +157,7 @@ class Circuit(object):
         d.addCallback(close_command_is_queued)
         return self._closing_deferred
 
-    def age(self, now=datetime.datetime.utcnow()):
+    def age(self, now=None):
         """
         Returns an integer which is the difference in seconds from
         'now' to when this circuit was created.
@@ -166,6 +166,8 @@ class Circuit(object):
         """
         if not self.time_created:
             return None
+        if now == None:
+            now = datetime.datetime.utcnow()
         return (now - self.time_created).seconds
 
     def _create_flags(self, kw):

-- 
Happy hacking
Petter Reinholdtsen

--- End Message ---
--- Begin Message ---
Hi,

This was fixed in a debian version that wasn't uploaded (0.15.1-1) due to me
having signing key issues. The fix for this is present in 0.16.1-1.

Thanks,
Iain.

Attachment: signature.asc
Description: PGP signature


--- End Message ---

Reply via email to