Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore backup: django.core.serializers.base.DeserializationError: Input string must be text, not bytes #1597

Closed
tobiasmuehl opened this issue Jul 27, 2022 · 1 comment

Comments

@tobiasmuehl
Copy link

Self-Hosted Version

22.7.0

CPU Architecture

x86_64

Docker Version

20.10.17

Docker Compose Version

2.6.0

Steps to Reproduce

  1. Install sentry
  2. change "Open Membership" setting to false in admin panel
  3. create backup file as indicated in docs: docker-compose run --rm -T -e SENTRY_LOG_LEVEL=CRITICAL web export > sentry/backup.json
  4. docker compose down
  5. docker volume rm $(docker volume ls -q)
  6. ./install.sh
  7. Restore backup docker-compose run --rm -T web import /etc/sentry/backup.json

Expected Result

Backup is restored successfully

Actual Result

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/django/core/serializers/python.py", line 143, in Deserializer
    data[field.name] = field.to_python(field_value)
  File "/usr/local/lib/python3.8/site-packages/sentry/db/models/fields/picklefield.py", line 54, in to_python
    return json.loads(value)
  File "/usr/local/lib/python3.8/site-packages/sentry/utils/json.py", line 114, in loads
    return _default_decoder.decode(value)
  File "/usr/local/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.8/site-packages/simplejson/decoder.py", line 392, in raw_decode
    raise TypeError("Input string must be text, not bytes")
TypeError: Input string must be text, not bytes

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/sentry", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/site-packages/sentry/runner/__init__.py", line 188, in main
    func(**kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/sentry/runner/decorators.py", line 29, in inner
    return ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/sentry/runner/commands/backup.py", line 19, in import_
    for obj in serializers.deserialize("json", src, stream=True, use_natural_keys=True):
  File "/usr/local/lib/python3.8/site-packages/django/core/serializers/json.py", line 69, in Deserializer
    yield from PythonDeserializer(objects, **options)
  File "/usr/local/lib/python3.8/site-packages/django/core/serializers/python.py", line 145, in Deserializer
    raise base.DeserializationError.WithData(e, d['model'], d.get('pk'), field_value)
django.core.serializers.base.DeserializationError: Input string must be text, not bytes: (sentry.option:pk=5) field_value was 'False'

To fix it, I had to manually patch the JSON

{
  "model": "sentry.option",
  "pk": 5,
  "fields": {
    "key": "auth.allow-registration",
-    "value": false,
+    "value": "false",
    "last_updated": "2022-07-13T11:31:28.985Z"
  }
},


This issue happened for multiple objects that are of number or boolean type. Wrapping in quotes worked in all instances.
@aminvakil
Copy link
Collaborator

Duplicate of getsentry/sentry#36868 .

@tobiasmuehl Please follow that issue, thanks!

@aminvakil aminvakil closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Aug 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants