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

YAMLRenderer - RepresenterError : cannot represent an object: ReturnDict #2283

Closed
davidfischer-ch opened this issue Dec 16, 2014 · 4 comments · Fixed by #2315
Closed

YAMLRenderer - RepresenterError : cannot represent an object: ReturnDict #2283

davidfischer-ch opened this issue Dec 16, 2014 · 4 comments · Fixed by #2315
Labels
Milestone

Comments

@davidfischer-ch
Copy link

davidfischer-ch commented Dec 16, 2014

Tested with django-rest-framework 3.0 dd712a1 under python 3.4 and with a recent django (1.8+)

Environment:

Request Method: GET
Request URL: http://192.168.56.101/fr/api/v1/media/5604d858-f592-4338-aaa3-73293364c8db?format=yaml

Django Version: 1.8.dev20141120151358
Python Version: 3.4.0
Installed Applications:
['django_admin_bootstrapped',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.humanize',
 'django.contrib.messages',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.staticfiles',
  ...
 'rest_framework',
 'debug_toolbar',
 'template_timings_panel']
Installed Middleware:
['debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'project.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Traceback:
File "/var/project/prod/venv/src/django/django/core/handlers/base.py" in get_response
  157.                 response = response.render()
File "/var/project/prod/venv/src/django/django/template/response.py" in render
  104.             self.content = self.rendered_content
File "/var/project/prod/venv/src/django-rest-framework/rest_framework/response.py" in rendered_content
  59.         ret = renderer.render(self.data, media_type, context)
File "/var/project/prod/venv/src/django-rest-framework/rest_framework/renderers.py" in render
  218.         return yaml.dump(data, stream=None, encoding=self.charset, Dumper=self.encoder, allow_unicode=not self.ensure_ascii)
File "/usr/local/lib/python3.4/dist-packages/yaml/__init__.py" in dump
  200.     return dump_all([data], stream, Dumper=Dumper, **kwds)
File "/usr/local/lib/python3.4/dist-packages/yaml/__init__.py" in dump_all
  188.             dumper.represent(data)
File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py" in represent
  26.         node = self.represent_data(data)
File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py" in represent_data
  57.                     node = self.yaml_representers[None](self, data)
File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py" in represent_undefined
  227.         raise RepresenterError("cannot represent an object: %s" % data)

Exception Type: RepresenterError at /fr/api/v1/media/5604d858-f592-4338-aaa3-73293364c8db
Exception Value: cannot represent an object: ReturnDict([('api_url', 'http://192.168.56.101/fr/api/v1/media/5604d858-f592-4338-aaa3-73293364c8db'), ('uuid', '5604d858-f592-4338-aaa3-73293364c8db'), ('title', 'Divergent 1080p (transcoded)'), ('file', 'http://192.168.56.101/protected/media/5604d858-f592-4338-aaa3-73293364c8db/Divergent%201080p%2000%3A02%3A40-00%3A03%3A40%20transcoded.mkv'), ('url', None), ('md5_checksum', None), ('metadatas', None), ('keyword_set', []), ('state', 'BROKEN'), ('parent', 'http://192.168.56.101/fr/api/v1/media/5ff1ba6f-c7c5-45ff-ae28-29b3621b5d98'), ('created_by', 2), ('created_at', '2014-12-11T08:30:45.052558Z'), ('updated_at', '2014-12-11T08:30:45.254961Z'), ('infos', None), ('is_upload', False), ('meta', OrderedDict([('duration', '0:00:00'), ('framerate', 0.0), ('interlaced', None), ('size', 0), ('width', 0), ('height', 0), ('content_width', 0), ('content_height', 0), ('content_x', 0), ('content_y', 0)]))])
@jpadilla
Copy link
Member

jpadilla commented Dec 16, 2014

I think we need some more information here. Can you share some code? Was this also happening from the latest released version in PyPI?

@tomchristie
Copy link
Member

tomchristie commented Dec 18, 2014

Verified. Run the quickstart and add rest_framework.renderers.YAMLRenderer to your REST_FRAMEWORK settings dict.

@tomchristie
Copy link
Member

tomchristie commented Dec 18, 2014

Thanks for the report @davidfischer-ch. Now resolved in master - fix will be in the 3.0.3 release.

@davidfischer-ch
Copy link
Author

davidfischer-ch commented Dec 18, 2014

Awesome! I will use it soon!

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

Successfully merging a pull request may close this issue.

3 participants