Improve error reporting when sending wrong image format (was: Posting an Image generates an error "'NoneType' object has no attribute 'url'")
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 109
- Forks
- 107
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 4
Description
I am using the RestApi v3.5.0 on Plone 5.1.4. I am able to create Document and File objects with no problem. However, posting an image consistently generates "'NoneType' object has no attribute 'url'". It seems like posting base64 image data shouldn't require a URL. I'm guessing I have the deserialization format incorrect. The only well documented format is for File which works fine.
Example Post body:
{
"@type": "Image",
"image": {
"content-type": "image/jpeg",
"data": "<<base64 data goes here>>",
"encoding": "base64",
"filename": "e.jpeg"
},
"title": "My image"
}
Resulting error message:
{
"message": "'NoneType' object has no attribute 'url'",
"traceback": [
"File \"/home/vagrant/Plone/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/ZPublisher/Publish.py\", line 138, in publish",
" request, bind=1)",
"",
" File \"/home/vagrant/Plone/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/ZPublisher/mapply.py\", line 77, in mapply",
" if debug is not None: return debug(object,args,context)",
"",
" File \"/home/vagrant/Plone/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/ZPublisher/Publish.py\", line 48, in call_object",
" result=apply(object,args) # Type s<cr> to step into published object.",
"",
" File \"/home/vagrant/Plone/buildout-cache/eggs/plone.rest-1.4.0-py2.7.egg/plone/rest/service.py\", line 23, in __call__",
" return self.render()",
"",
" File \"/home/vagrant/Plone/buildout-cache/eggs/plone.restapi-3.5.0-py2.7.egg/plone/restapi/services/__init__.py\", line 19, in render",
" content = self.reply()",
"",
" File \"/home/vagrant/Plone/buildout-cache/eggs/plone.restapi-3.5.0-py2.7.egg/plone/restapi/services/content/add.py\", line 93, in reply",
" serialized_obj = serializer()",
"",
" File \"/home/vagrant/Plone/buildout-cache/eggs/plone.restapi-3.5.0-py2.7.egg/plone/restapi/serializer/dxcontent.py\", line 84, in __call__",
" value = serializer()",
"",
" File \"/home/vagrant/Plone/buildout-cache/eggs/plone.restapi-3.5.0-py2.7.egg/plone/restapi/serializer/dxfields.py\", line 48, in __call__",
" height,",
"",
" File \"/home/vagrant/Plone/buildout-cache/eggs/plone.restapi-3.5.0-py2.7.egg/plone/restapi/imaging.py\", line 56, in get_original_image_url",
" return scale.url"
],
"type": "AttributeError"
}
Any guidance here would be greatly appreciated.
-- Don
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the POST using the example body, then inspect plone/restapi/imaging.py at get_original_image_url and the serializer path in serializer/dxfields.py. Trace how an Image with base64 data reaches the failing URL lookup. Done means the wrong image format or missing URL produces a clear, actionable error instead of the NoneType traceback.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100