Skip to content

Commit

Permalink
Package: convert size property to integer
Browse files Browse the repository at this point in the history
Manually dehydrate `BigIntegerField` as an integer since Tastypie can't do
that for us (django-tastypie/django-tastypie#299).

Connects to archivematica/Issues#1094.
  • Loading branch information
sevein committed Feb 26, 2020
1 parent 1e9f87a commit 30fbc3b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions storage_service/locations/api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 30fbc3b

Please sign in to comment.