diff --git a/storage_service/locations/api/resources.py b/storage_service/locations/api/resources.py index 1a2da9a7d..692a43d07 100644 --- a/storage_service/locations/api/resources.py +++ b/storage_service/locations/api/resources.py @@ -909,6 +909,17 @@ def dehydrate(self, bundle): bundle.data["encrypted"] = encrypted return bundle + def dehydrate_size(self, bundle): + """Ensure that ``size`` is serialized as an integer. + + This is needed because Tastypie doesn't know how to dehydrate + ``BigIntegerField`` (see django-tastypie/django-tastypie#299). + """ + try: + return int(bundle.data["size"]) + except (ValueError, TypeError, KeyError): + return 0 + def hydrate_current_location(self, bundle): """Customize unserialization of current_location.