From f95677d1adf725d48c984cd72e82f4472fc2996c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 10 Aug 2015 11:07:08 +0200 Subject: [PATCH] Fix TypeError during min/max computation in Graph If the field is a datetime, a date or a timedelta but the value if None, it could be compared to an existing instance and so raise a TypeError. So the min/max value must be set with a correct value and TypeError must be catched if the record value is None. issue4888 review16501002 --- .../gui/window/view_form/view/graph_gtk/graph.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tryton/gui/window/view_form/view/graph_gtk/graph.py b/tryton/gui/window/view_form/view/graph_gtk/graph.py index 642a55e803..67d7c1037a 100644 --- a/tryton/gui/window/view_form/view/graph_gtk/graph.py +++ b/tryton/gui/window/view_form/view/graph_gtk/graph.py @@ -355,8 +355,18 @@ class Graph(gtk.DrawingArea): minx = x if not maxx: maxx = x - minx = min(minx, x) - maxx = max(maxx, x) + if minx is None and maxx is None: + if isinstance(x, datetime.datetime): + minx, maxx = datetime.datetime.min, datetime.datetime.max + elif isinstance(x, datetime.date): + minx, maxx = datetime.date.min, datetime.date.max + elif isinstance(x, datetime.timedelta): + minx, maxx = datetime.timedelta.min, datetime.timedelta.max + try: + minx = min(minx, x) + maxx = max(maxx, x) + except TypeError: + continue self.labels[x] = model[self.xfield['name']].get_client(model) self.ids.setdefault(x, []) self.ids[x].append(model.id)