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

use value.url for both FieldFile and FileField #184

Open
sachazyto opened this issue Dec 15, 2015 · 0 comments
Open

use value.url for both FieldFile and FileField #184

sachazyto opened this issue Dec 15, 2015 · 0 comments

Comments

@sachazyto
Copy link

Using django 1.8.4, I'm getting the following error when trying to serialize a FileField:
<FieldFile: sampleapp/img5_L3sBxJI.png> is not JSON serializable
Traceback:
[...]
File "/home/vagrant/.venvs/infra_env/local/lib/python2.7/site-packages/swampdragon/models.py" in save

  1.     self._publish(self.action, self.changed_fields)
    
    File "/home/vagrant/.venvs/infra_env/local/lib/python2.7/site-packages/swampdragon/models.py" in _publish
  2.     publish_model(self, self._serializer, action, changed_fields)
    
    File "/home/vagrant/.venvs/infra_env/local/lib/python2.7/site-packages/swampdragon/pubsub_providers/model_publisher.py" in publish_model
  3.         publisher.publish(c, publish_data)
    
    File "/home/vagrant/.venvs/infra_env/local/lib/python2.7/site-packages/swampdragon/pubsub_providers/redis_publisher.py" in publish
  4. get_redis_cli().publish(channel, json.dumps(message))
    
    File "/usr/lib/python2.7/json/init.py" in dumps
  5.     return _default_encoder.encode(obj)
    
    File "/usr/lib/python2.7/json/encoder.py" in encode
  6.     chunks = self.iterencode(o, _one_shot=True)
    
    File "/usr/lib/python2.7/json/encoder.py" in iterencode
  7.     return _iterencode(o, 0)
    
    File "/usr/lib/python2.7/json/encoder.py" in default
  8.     raise TypeError(repr(o) + " is not JSON serializable")
    

Exception Type: TypeError at /admin/mapping/tile/5/
Exception Value: <FieldFile: sampleapp/img5_L3sBxJI.png> is not JSON serializable

The problem seems to be in https://github.com/jonashagstedt/swampdragon/blob/master/swampdragon/serializers/field_serializers.py#L34 we're checking if type of of the 'value' is a FileField, but it's actually a FieldFile as described in the traceback above and explained at https://docs.djangoproject.com/en/1.8/ref/models/fields/#filefield-and-fieldfile.

Hence, I think we should be using FileSerializer in the case where value is a FieldFile as well.

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