[dataformats] Invalid data format may generate 500 error on "fork"
Upon forking a dataformat, the user may slightly modify the said format and generate an internal logical error leading to a 500 page displayed.
I just received this e-mail from our beat.web server:
Internal Server Error: /platform/dataformats/fork/chichan/a-collection-of-linear_machines/1/
Traceback (most recent call last):
File "/remote/sw/beat.env.web-0.0.1/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/remote/sw/beat.env.web-0.0.1/usr/lib/python2.7/site-packages/django/utils/decorators.py", line 110, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/remote/sw/beat.env.web-0.0.1/usr/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/remote/sw/beat.web/src/beat.web/beat/web/dataformats/views.py", line 165, in fork_dataformat
dataformat.author.username,
AttributeError: 'NoneType' object has no attribute 'author'
Indeed, this bit of code needs protection:
if form.is_valid():
(dataformat, errors) = DataFormat.objects.create_dataformat(
author=request.user,
name=form.cleaned_data['name'],
short_description=form.cleaned_data['short_description'],
description=form.cleaned_data['description'],
declaration=form.cleaned_data['file'],
fork_of=fork_of
)
# Redirect to the page of the dataformat just created
return HttpResponseRedirect(
reverse('dataformats-view',
args=(
dataformat.author.username,
dataformat.name,
dataformat.version,
),
)
)
For example, it does not handle the case in which the "validation" generates an error and the returned data format is None
, generating the error above. This code must be corrected both on the branch "0.14" as well as on the "master" branch.