milesmcc / shynet

Modern, privacy-friendly, and detailed web analytics that works without cookies or JS.
Apache License 2.0
2.93k stars 190 forks source link

Incorrect calculation of month value #185

Closed wolfpld closed 2 years ago

wolfpld commented 2 years ago
shynet_main  | [2022-01-01 00:04:18 +0000] [9] [INFO] Booting worker with pid: 9
shynet_main  | ERROR Internal Server Error: /dashboard/
shynet_main  | Traceback (most recent call last):
shynet_main  |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
shynet_main  |     response = get_response(request)
shynet_main  |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
shynet_main  |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
shynet_main  |   File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
shynet_main  |     return self.dispatch(request, *args, **kwargs)
shynet_main  |   File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/mixins.py", line 71, in dispatch
shynet_main  |     return super().dispatch(request, *args, **kwargs)
shynet_main  |   File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 98, in dispatch
shynet_main  |     return handler(request, *args, **kwargs)
shynet_main  |   File "/usr/local/lib/python3.9/site-packages/django/views/generic/list.py", line 157, in get
shynet_main  |     context = self.get_context_data()
shynet_main  |   File "/usr/src/shynet/dashboard/views.py", line 36, in get_context_data
shynet_main  |     data = super().get_context_data(**kwargs)
shynet_main  |   File "/usr/src/shynet/dashboard/mixins.py", line 64, in get_context_data
shynet_main  |     data["date_ranges"] = self.get_date_ranges()
shynet_main  |   File "/usr/src/shynet/dashboard/mixins.py", line 50, in get_date_ranges
shynet_main  |     "start": now.replace(day=1, month=now.month - 1),
shynet_main  | ValueError: month must be in 1..12
REPOSITORY                TAG           IMAGE ID       CREATED
milesmcc/shynet           latest        8fc7868f03dd   3 months ago
fightforlife commented 2 years ago

Exactly the same error here starting on years change.

milesmcc commented 2 years ago

Hmm. Seeing it myself as well. TIL that January 2022 is actually month 13 of 2021.

milesmcc commented 2 years ago

Fixed in https://github.com/milesmcc/shynet/commit/4b4c8f207e94ac1b692d75e0ee826c55fbe23a14. Will release shortly — in the meantime, the fixed build should be up on :edge in a few minutes.

milesmcc commented 2 years ago

Fixed in v0.12.0, released just now. Happy new year!

haaavk commented 2 years ago

It could be fixed by:

            {
                "name": "Last month",
                "start": (now.replace(day=1) - timezone.timedelta(days=1)).replace(
                    day=1
                ),
                "end": now.replace(day=1) - timezone.timedelta(days=1),
            },

I can add PR with that.

milesmcc commented 2 years ago

Yep, that also makes sense. Would accept that PR.