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
This commit is contained in:
1 parent
a402de9ad3
commit
f95677d1ad
1 file changed
+12
-2
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user