RSE-Sheffield / RSEAdmin

A Resource Allocation and Finance tool for RSE Groups
https://rseadmin.readthedocs.io/en/latest/
MIT License
24 stars 6 forks source link

ZeroDivisionError #175

Closed grenville closed 2 years ago

grenville commented 2 years ago

Hi

Trying to view a project I get:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8080/client/1

Django Version: 3.2.5
Python Version: 3.9.5
Installed Applications:
['polymorphic',
 'rse.apps.RseConfig',
 'timetracking.apps.TimetrackingConfig',
 'django_adminlte',
 'django_adminlte_theme',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize']
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']

Template error:
In template /home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django_adminlte/templates/adminlte/base.html, error at line 69
   float division by zero
   59 :                 {% block content_block_wrap %}
   60 :                     {% block content %}{% endblock %}
   61 :                 {% endblock %}
   62 :             </section>
   63 :             {% endblock %}
   64 : 
   65 :         </div>
   66 :         {% endblock content_wrapper %}
   67 : 
   68 :         {% block nav_footer %}
   69 :              {% include 'adminlte/lib/ _main_footer.html' %}
   70 :         {% endblock %}
   71 : 
   72 :     </div>
   73 : {% endblock body %}
   74 : 
   75 : {% block javascript %}
   76 : {% include 'adminlte/lib/_scripts.html' %}
   77 : {% endblock %}
   78 : 
   79 : {% block extra_foot %}{% endblock %}

Traceback (most recent call last):
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 829, in _resolve_lookup
    current = current[bit]

During handling of the above exception ('AllocatedProject' object is not subscriptable), another exception occurred:
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/grenville/RSEAdmin/rse/views/clients.py", line 54, in client
    return render(request, 'client.html', view_dict)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 170, in render
    return self._render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/defaulttags.py", line 211, in render
    nodelist.append(node.render_annotated(context))
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 988, in render
    output = self.filter_expression.resolve(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 671, in resolve
    obj = self.var.resolve(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 796, in resolve
    value = self._resolve_lookup(context)
  File "/home/grenville/.cache/pypoetry/virtualenvs/rseadmin-uz1Mmgim-py3.9/lib/python3.9/site-packages/django/template/base.py", line 837, in _resolve_lookup
    current = getattr(current, bit)
  File "/home/grenville/RSEAdmin/rse/models.py", line 771, in percent_allocated
    return round(self.committed_days / self.project_days * 100, 2)

Exception Type: ZeroDivisionError at /client/1
Exception Value: float division by zero
grenville commented 2 years ago

I'd really like to use the software, but this is preventing me from seeing a list of projects

mondus commented 2 years ago

Hi @grenville . This is clearly a bug that needs fixing. It is occurring presumably because you have a project which has a duration of 0 days (an edge case I didn't consider). Can you trying viewing your projects through the django admin interface to see if this is true? If it is you can modify your projects start/end date to avoid this issue until I put a proper bug fix in place.

Edit: Just to note this could also occur is FTE for an allocated project is 0%.

grenville commented 2 years ago

Hi @mondus, thanks - a data entry error on my part. I fiddled with the code that was dividing by zero to move on (fiddling with code is the last thing I want to do) Grenville