Skip to content

Commit

Permalink
Merge pull request #205 from tmaeno/master
Browse files Browse the repository at this point in the history
for Decimal in getJobStatisticsPerSite's return
  • Loading branch information
tmaeno authored Apr 19, 2023
2 parents 539a661 + abfc717 commit 602fe32
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 602fe32

Please sign in to comment.