cvsslib icon indicating copy to clipboard operation
cvsslib copied to clipboard

Unable to save object via django-admin

Open 0secure opened this issue 8 years ago • 0 comments

When saving a cvss2 object from the django admin interface, an AttributeError is received. This error appears to be because the value (0.35, etc) is being saved as a string instead of a number. If I attempt to save the object via the command line with numeric values, it succeeds. When i attempt to save a value as a string, I receive the same attribute error as I receive via the GUI.

Relevant code:

CVSS2Base = django_mixin(cvss2, attr_name="CVSS2Base")
class CVSS2(models.Model, metaclass=CVSS2Base):
    pass

x = CVSS2()
x.exploitability=0.85
x.save() #works

x.exploitability='0.85'
x.save() #AttributeError, same as django-admin

Traceback below:

Environment:

Request Method: POST
Request URL: http://___.com/vm/admin/vm/cvss2/1/change/

Django Version: 1.11.5
Python Version: 3.6.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'vm.apps.VMConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/usr/lib64/python3.6/enum.py" in __getattr__
  322.             return cls._member_map_[name]

During handling of the above exception ('0.35'), another exception occurred:

File "/usr/lib64/python3.6/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/usr/lib64/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/usr/lib64/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/lib64/python3.6/site-packages/django/contrib/admin/options.py" in wrapper
  551.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/usr/lib64/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "/usr/lib64/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)

File "/usr/lib64/python3.6/site-packages/django/contrib/admin/sites.py" in inner
  224.             return view(request, *args, **kwargs)

File "/usr/lib64/python3.6/site-packages/django/contrib/admin/options.py" in change_view
  1511.         return self.changeform_view(request, object_id, form_url, extra_context)

File "/usr/lib64/python3.6/site-packages/django/utils/decorators.py" in _wrapper
  67.             return bound_func(*args, **kwargs)

File "/usr/lib64/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "/usr/lib64/python3.6/site-packages/django/utils/decorators.py" in bound_func
  63.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/usr/lib64/python3.6/site-packages/django/contrib/admin/options.py" in changeform_view
  1408.             return self._changeform_view(request, object_id, form_url, extra_context)

File "/usr/lib64/python3.6/site-packages/django/contrib/admin/options.py" in _changeform_view
  1440.             if form.is_valid():

File "/usr/lib64/python3.6/site-packages/django/forms/forms.py" in is_valid
  183.         return self.is_bound and not self.errors

File "/usr/lib64/python3.6/site-packages/django/forms/forms.py" in errors
  175.             self.full_clean()

File "/usr/lib64/python3.6/site-packages/django/forms/forms.py" in full_clean
  384.         self._clean_fields()

File "/usr/lib64/python3.6/site-packages/django/forms/forms.py" in _clean_fields
  402.                     value = field.clean(value)

File "/usr/lib64/python3.6/site-packages/django/forms/fields.py" in clean
  864.         return self._coerce(value)

File "/usr/lib64/python3.6/site-packages/django/forms/fields.py" in _coerce
  853.             value = self.coerce(value)

File "/usr/lib/python3.6/site-packages/cvsslib/contrib/django_model.py" in to_python
  23.             return getattr(self.enum, value)

File "/usr/lib64/python3.6/enum.py" in __getattr__
  324.             raise AttributeError(name) from None

Exception Type: AttributeError at /vm/admin/vm/cvss2/1/change/
Exception Value: 0.35

0secure avatar Sep 12 '17 10:09 0secure