Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/sentry/db/models/fields/encrypted.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import six

from django.db.models import CharField, TextField
from picklefield.fields import PickledObjectField
from picklefield.fields import PickledObjectField, dbsafe_decode, PickledObject, _ObjectWrapper
from sentry.db.models.fields.jsonfield import JSONField
from sentry.db.models.utils import Creator
from sentry.utils.encryption import decrypt, encrypt
Expand Down Expand Up @@ -56,7 +56,24 @@ def get_db_prep_value(self, value, *args, **kwargs):
def to_python(self, value):
if value is not None and isinstance(value, six.string_types):
value = decrypt(value)
return super(EncryptedPickledObjectField, self).to_python(value)

# The following below is a copypaste of PickledObjectField.to_python of
# v1.0.0 with one change: We re-raise any baseexceptions such as
# signals. 1.0.0 has a bare `except:` which causes issues.

if value is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite honestly I would always reraise. If depickling fails, why would I ever want the raw value to be returned?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought this method had to be idempotent because of django?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this is expected to be idempotent. Let's try it like this first.

try:
value = dbsafe_decode(value, self.compress)
except Exception:
# If the value is a definite pickle; and an error is raised in
# de-pickling it should be allowed to propogate.
if isinstance(value, PickledObject):
raise
else:
if isinstance(value, _ObjectWrapper):
return value._obj

return value


class EncryptedTextField(TextField):
Expand Down