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

Object of type CharField is not JSON serializable #144

Open
ayushin opened this issue Jul 24, 2020 · 0 comments
Open

Object of type CharField is not JSON serializable #144

ayushin opened this issue Jul 24, 2020 · 0 comments

Comments

@ayushin
Copy link

ayushin commented Jul 24, 2020

Getting this error in the admin, anybody any clue? commenting out no problem: # location =PlainLocationField(based_fields=[street], zoom=7, null=True, blank=True)

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/console/machines/aquamachine/ff7917b2-3ebf-1dd2-f4d7-674aaaf3a383/change/

Django Version: 3.0.8
Python Version: 3.7.7
Installed Applications:
['accounts',
 'machines',
 'phonenumber',
 'rest_framework',
 'django_filters',
 'drf_yasg',
 'rest_framework.authtoken',
 'dj_rest_auth',
 'phonenumber_field',
 'mailer',
 'django_extensions',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'location_field.apps.DefaultConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django_currentuser.middleware.ThreadLocalUserMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'aqua.middleware.HealthCheckMiddleware']


Template error:
In template /Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/contrib/admin/templates/admin/includes/fieldset.html, error at line 19
   Object of type CharField is not JSON serializable
   9 :             {% for field in line %}
   10 :                 <div{% if not line.fields|length_is:'1' %} class="fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
   11 :                     {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
   12 :                     {% if field.is_checkbox %}
   13 :                         {{ field.field }}{{ field.label_tag }}
   14 :                     {% else %}
   15 :                         {{ field.label_tag }}
   16 :                         {% if field.is_readonly %}
   17 :                             <div class="readonly">{{ field.contents }}</div>
   18 :                         {% else %}
   19 :                              {{ field.field }} 
   20 :                         {% endif %}
   21 :                     {% endif %}
   22 :                     {% if field.field.help_text %}
   23 :                         <div class="help">{{ field.field.help_text|safe }}</div>
   24 :                     {% endif %}
   25 :                 </div>
   26 :             {% endfor %}
   27 :         </div>
   28 :     {% endfor %}
   29 : </fieldset>


Traceback (most recent call last):
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/core/handlers/base.py", line 145, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/core/handlers/base.py", line 143, in _get_response
    response = response.render()
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 171, in render
    return self._render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/defaulttags.py", line 209, in render
    nodelist.append(node.render_annotated(context))
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/loader_tags.py", line 188, in render
    return template.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 173, in render
    return self._render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/defaulttags.py", line 209, in render
    nodelist.append(node.render_annotated(context))
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/defaulttags.py", line 209, in render
    nodelist.append(node.render_annotated(context))
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/defaulttags.py", line 309, in render
    return nodelist.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/defaulttags.py", line 309, in render
    return nodelist.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 992, in render
    return render_value_in_context(output, context)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/template/base.py", line 971, in render_value_in_context
    value = str(value)
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/utils/html.py", line 373, in <lambda>
    klass.__str__ = lambda self: mark_safe(klass_str(self))
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/forms/boundfield.py", line 33, in __str__
    return self.as_widget()
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/django/forms/boundfield.py", line 96, in as_widget
    renderer=self.form.renderer,
  File "/Users/alexis/Work/Python/.virtualenvs/aqua/lib/python3.7/site-packages/location_field/widgets.py", line 48, in render
    attrs['data-location-field-options'] = json.dumps(self.options)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '

Exception Type: TypeError at /console/machines/aquamachine/ff7917b2-3ebf-1dd2-f4d7-674aaaf3a383/change/
Exception Value: Object of type CharField is not JSON serializable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant