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

ZeroDivisionError in render function #89

Closed
Soneji opened this issue Jan 10, 2021 · 14 comments
Closed

ZeroDivisionError in render function #89

Soneji opened this issue Jan 10, 2021 · 14 comments
Labels
bug Something isn't working

Comments

@Soneji
Copy link

Soneji commented Jan 10, 2021

Hi

I am having an issue with shynet for only one of my accounts. Is there any way to fix this or put it into a try/except? Maybe have a value this expression defaults to if there is an error?

Thank you

shynet_1  | ERROR Internal Server Error: /dashboard/
shynet_1  | Traceback (most recent call last):
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
shynet_1  |     response = get_response(request)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 202, in _get_response
shynet_1  |     response = response.render()
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/response.py", line 105, in render
shynet_1  |     self.content = self.rendered_content
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/response.py", line 83, in rendered_content
shynet_1  |     return template.render(context, self._request)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
shynet_1  |     return self.template.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 170, in render
shynet_1  |     return self._render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
shynet_1  |     return self.nodelist.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
shynet_1  |     bit = node.render_annotated(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
shynet_1  |     return self.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 150, in render
shynet_1  |     return compiled_parent._render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
shynet_1  |     return self.nodelist.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
shynet_1  |     bit = node.render_annotated(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
shynet_1  |     return self.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
shynet_1  |     result = block.nodelist.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
shynet_1  |     bit = node.render_annotated(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
shynet_1  |     return self.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
shynet_1  |     result = block.nodelist.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
shynet_1  |     bit = node.render_annotated(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
shynet_1  |     return self.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/defaulttags.py", line 211, in render
shynet_1  |     nodelist.append(node.render_annotated(context))
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
shynet_1  |     return self.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 192, in render
shynet_1  |     return template.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 172, in render
shynet_1  |     return self._render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
shynet_1  |     return self.nodelist.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
shynet_1  |     bit = node.render_annotated(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
shynet_1  |     return self.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/defaulttags.py", line 516, in render
shynet_1  |     return self.nodelist.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
shynet_1  |     bit = node.render_annotated(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
shynet_1  |     return self.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/library.py", line 234, in render
shynet_1  |     return t.render(new_context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 172, in render
shynet_1  |     return self._render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
shynet_1  |     return self.nodelist.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
shynet_1  |     bit = node.render_annotated(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
shynet_1  |     return self.render(context)
shynet_1  |   File "/usr/local/lib/python3.9/site-packages/django/template/library.py", line 192, in render
shynet_1  |     output = self.func(*resolved_args, **resolved_kwargs)
shynet_1  |   File "/usr/src/shynet/dashboard/templatetags/helpers.py", line 76, in percent_change_display
shynet_1  |     change = int(round(100 * abs(end - start) / start))
shynet_1  | ZeroDivisionError: division by zero
@milesmcc milesmcc added the bug Something isn't working label Jan 10, 2021
@milesmcc
Copy link
Owner

Thanks! Fixed in v0.7.2. It will be published to Docker Hub shortly. Let me know if you run into any issues.

@Soneji
Copy link
Author

Soneji commented Jan 10, 2021

Hi @milesmcc

Your fix appears to not have actually fixed my error. Maybe a try/except would work better?

I am now getting:

shynet_1  |   File "/usr/src/shynet/dashboard/templatetags/helpers.py", line 76, in percent_change_display
shynet_1  |     change = int(round(100 * abs(end - start) / max(start, 1)))
shynet_1  | TypeError: '>' not supported between instances of 'int' and 'datetime.timedelta'

@milesmcc
Copy link
Owner

A try/except could work, except I'd rather solve the root issue. In this case, I think a try/catch would only mask other issues (and would be bad style). Datetimes shouldn't be running through percent_change_display. I'll dig a bit further.

@milesmcc
Copy link
Owner

I'm having trouble replicating this error. I see from your original error report that this is happening on /dashboard. Could you provide me with more information about what is going on? For example, starting with a completely empty Shynet instance, what do you need to do to see this error?

@Soneji
Copy link
Author

Soneji commented Jan 10, 2021

I am also very confused about why this error is occuring, but I have setup a shynet instance around August 2020 and the error just manifested itself. I think it may be an issue with the some database data, but it has obviously occured by itself over time. Additionally, the error only occurs for one of the users in my shynet instance, making me think it is related to one of their sites.

Can this issue be re-opened?

@Soneji
Copy link
Author

Soneji commented Jan 10, 2021

I am happy to run modifications to my local shynet repo, with the existing database, to help debug the issue.

I will change my docker-compose file to build: . instead of image:

@milesmcc milesmcc reopened this Jan 10, 2021
@zmiguel
Copy link

zmiguel commented Jan 11, 2021

Same issue here, running on docker

@milesmcc
Copy link
Owner

@zmiguel and @Soneji -- could either of you let me know the steps you need to take to see this issue? When does it happen? Is it for the primary admin user? Is it for non-admin users? Reproduction steps would be very helpful! Thanks.

@milesmcc
Copy link
Owner

For now, I've just added a try/catch as @Soneji mentioned. I'd like to change this in the future once I isolate the issue, but it should fix things for now.

@Soneji
Copy link
Author

Soneji commented Jan 11, 2021

Thank you @milesmcc
This has fixed the issue for me.
I would still be happy to help you debug the problem in the future

@zmiguel
Copy link

zmiguel commented Jan 11, 2021

@milesmcc I'm not sure what caused it, I have 3 sites running that I had set up a few weeks ago, and yesterday the dashboard just stopped working for me.
I only have one user so yes this happens on the primary admin user.

Your last change did fix it.

@milesmcc
Copy link
Owner

Got it. @zmiguel -- would you mind sending a (redacted, if necessary) photo of the dashboard? Thanks! Specifically, I'm curious if any of the net change indicators have ? in them.

@zmiguel
Copy link

zmiguel commented Jan 11, 2021

@milesmcc you mean like that on the first one?

Screenshot

7351f4a5-4423-480a-b328-05d7f44d1fb4

@milesmcc
Copy link
Owner

Cool, got it. I'm going to reopen this issue now so that it stays on my mind to fix!

@milesmcc milesmcc reopened this Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants