Skip to content

Commit

Permalink
for Decimal in getJobStatisticsPerSite's return
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaeno committed Apr 19, 2023
1 parent 539a661 commit abfc717
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion PandaPkgInfo.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release_version = "0.0.50"
release_version = "0.0.51"
19 changes: 18 additions & 1 deletion pandaserver/taskbuffer/WrappedPickle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import decimal
from io import BytesIO
try:
# python 2
Expand All @@ -23,6 +24,20 @@ def __setattr__(self, key, value):
pickle.Unpickler.__setattr__(self, key, value)


# conversion for unserializable values
def conversion_func(item):
if isinstance(item, list):
return [conversion_func(i) for i in item]
if isinstance(item, dict):
return {k: conversion_func(item[k]) for k in item}
if isinstance(item, decimal.Decimal):
if item == item.to_integral_value():
item = int(item)
else:
item = float(item)
return item


# wrapper to avoid de-serializing unsafe objects
class WrappedPickle(object):
# allowed modules and classes
Expand Down Expand Up @@ -76,5 +91,7 @@ def loads(cls,pickle_string):

# dumps
@classmethod
def dumps(cls, obj):
def dumps(cls, obj, convert_to_safe=False):
if convert_to_safe:
obj = conversion_func(obj)
return pickle.dumps(obj, protocol=0)
2 changes: 1 addition & 1 deletion pandaserver/userinterface/UserIF.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def getJobStatisticsPerSite(self,predefined=False,workingGroup='',countryGroup='
ret = self.taskBuffer.getJobStatistics(readArchived,predefined,workingGroup,countryGroup,jobType,
minPriority=minPriority)
# serialize
return WrappedPickle.dumps(ret)
return WrappedPickle.dumps(ret, convert_to_safe=True)


# get job statistics per site and resource
Expand Down

0 comments on commit abfc717

Please sign in to comment.