# Buggy code
def put(self, request):
    # TODO(dcramer): this should validate options before saving them
    for k, v in six.iteritems(request.data):
        if v and isinstance(v, six.string_types):
            v = v.strip()
        try:
            option = options.lookup_key(k)
        except options.UnknownOption:
            # TODO(dcramer): unify API errors
            return Response(
                {"error": "unknown_option", "errorDetail": {"option": k}}, status=400
            )

        try:
            if not (option.flags & options.FLAG_ALLOW_EMPTY) and not v:
                options.delete(k)
            else:
                options.set(k, v)
        except TypeError as e:
            return Response(
                {
                    "error": "invalid_type",
                    "errorDetail": {"option": k, "message": six.text_type(e)},
                },
                status=400,
            )
    # TODO(dcramer): this has nothing to do with configuring options and
    # should not be set here
    options.set("sentry:version-configured", sentry.get_version())
    return Response(status=200)


# Traceback (AssertionError)
Oct  6 07:18:49 jsentry sentry[4128]: 10.100.33.5 - - [06/Oct/2020:04:18:49 +0000] "GET /api/0/internal/options/ HTTP/1.1" 200 20407 "https://sentry.findmykids.org/manage/settings/" "Mozilla/5.0 (X11; FreeBSD amd64; rv:76.0) Gecko/20100101 Firefox/76.0"
Oct  6 07:19:09 jsentry sentry[4128]: Traceback (most recent call last):
Oct  6 07:19:09 jsentry sentry[4128]:   File "/usr/local/lib/python2.7/site-packages/sentry-20.8.0-py2.7.egg/sentry/api/base.py", line 134, in handle_exception
Oct  6 07:19:09 jsentry sentry[4128]:     response = super(Endpoint, self).handle_exception(exc)
Oct  6 07:19:09 jsentry sentry[4128]:   File "/usr/local/lib/python2.7/site-packages/djangorestframework-3.6.4-py2.7.egg/rest_framework/views.py", line 449, in handle_exception
Oct  6 07:19:09 jsentry sentry[4128]:     self.raise_uncaught_exception(exc)
Oct  6 07:19:09 jsentry sentry[4128]:   File "/usr/local/lib/python2.7/site-packages/sentry-20.8.0-py2.7.egg/sentry/api/base.py", line 247, in dispatch
Oct  6 07:19:09 jsentry sentry[4128]:     response = handler(request, *args, **kwargs)
Oct  6 07:19:09 jsentry sentry[4128]:   File "/usr/local/lib/python2.7/site-packages/sentry-20.8.0-py2.7.egg/sentry/api/endpoints/system_options.py", line 74, in put
Oct  6 07:19:09 jsentry sentry[4128]:     options.set(k, v)
Oct  6 07:19:09 jsentry sentry[4128]:   File "/usr/local/lib/python2.7/site-packages/sentry-20.8.0-py2.7.egg/sentry/options/manager.py", line 83, in set
Oct  6 07:19:09 jsentry sentry[4128]:     "%r cannot be changed at runtime because it is configured on disk" % key
Oct  6 07:19:09 jsentry sentry[4128]: AssertionError: u'system.url-prefix' cannot be changed at runtime because it is configured on disk
Oct  6 07:19:09 jsentry sentry[4128]: 10.100.33.5 - - [06/Oct/2020:04:19:09 +0000] "PUT /api/0/internal/options/ HTTP/1.1" 500 746 "https://sentry.findmykids.org/manage/settings/" "Mozilla/5.0 (X11; FreeBSD amd64; rv:76.0) Gecko/20100101 Firefox/76.0"

# Fixed code
def put(self, request):
    # TODO(dcramer): this should validate options before saving them
    for k, v in six.iteritems(request.data):
        if v and isinstance(v, six.string_types):
            v = v.strip()
        try:
            option = options.lookup_key(k)
        except options.UnknownOption:
            # TODO(dcramer): unify API errors
            return Response(
                {"error": "unknown_option", "errorDetail": {"option": k}}, status=400
            )

        try:
            if not (option.flags & options.FLAG_ALLOW_EMPTY) and not v:
                options.delete(k)
            else:
                options.set(k, v)
        except (TypeError, AssertionError) as e:
            # TODO(chadwhitacre): Use a custom exception for the
            # immutability case, especially since asserts disappear with
            # `python -O`.
            return Response(
                {
                    "error": "invalid_type"
                    if type(e) is TypeError
                    else "immutable_option",
                    "errorDetail": {"option": k, "message": six.text_type(e)},
                },
                status=400,
            )
    # TODO(dcramer): this has nothing to do with configuring options and
    # should not be set here
    options.set("sentry:version-configured", sentry.get_version())
    return Response(status=200)