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

KeyError at /children/XXX/reports/sleep/pattern/ #211

Closed
BenjaminHae opened this issue May 1, 2021 · 4 comments
Closed

KeyError at /children/XXX/reports/sleep/pattern/ #211

BenjaminHae opened this issue May 1, 2021 · 4 comments
Labels
bug Reports of unexpected problems or errors

Comments

@BenjaminHae
Copy link
Contributor

I'm getting a key error when accessing the sleep pattern.
I'm using the current version from docker hub, but I'm using data I've migrated from an older version (can't say which version, probably from around March 2020.

Environment:
Request Method: GET
Request URL: http://babybuddy/children/XXX/reports/sleep/pattern/

Django Version: 3.2
Python Version: 3.8.9
Installed Applications:
['api',
 'babybuddy',
 'core',
 'dashboard',
 'reports',
 'django_filters',
 'rest_framework',
 'rest_framework.authtoken',
 'widget_tweaks',
 'easy_thumbnails',
 'storages',
 'import_export',
 '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',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'babybuddy.middleware.RollingSessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'babybuddy.middleware.UserTimezoneMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/mixins.py", line 104, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/views/generic/detail.py", line 107, in get
    context = self.get_context_data(object=self.object)
  File "/app/reports/views.py", line 131, in get_context_data
    context['html'], context['js'] = graphs.sleep_pattern(instances)
  File "/app/reports/graphs/sleep_pattern.py", line 88, in sleep_pattern
    times[yesterday][len(times[yesterday]) - 1] = duration.seconds/60

Exception Type: KeyError at /children/XXX/reports/sleep/pattern/
Exception Value: '2020-10-23'

Relevant local variables:

adj_start_time datetime.datetime(2020, 10, 25, 0, 0, tzinfo=<DstTzInfo 'Europe/Berlin' CET+1:00:00 STD>)
adjustment {'column': '2020-10-25', 'duration': datetime.timedelta(seconds=16200), 'end_time': datetime.datetime(2020, 10, 25, 4, 30, tzinfo=<DstTzInfo 'Europe/Berlin' CET+1:00:00 STD>), 'start_time': datetime.datetime(2020, 10, 25, 0, 0, tzinfo=<DstTzInfo 'Europe/Berlin' CET+1:00:00 STD>)}
diff datetime.timedelta(seconds=3600)
duration datetime.timedelta(seconds=13740)
end_time datetime.datetime(2020, 10, 24, 23, 59, tzinfo=<DstTzInfo 'Europe/Berlin' CET+1:00:00 STD>)
instance <Sleep: Schlafen>
instances <QuerySet [<Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, <Sleep: Schlafen>, '...(remaining elements truncated)...']>
labels {'2020-10-24': [None, 'Asleep 1 Stunde, 50 Minuten (07:40 AM to 09:30 AM)', None, 'Asleep 1 Stunde, 21 Minuten (11:54 AM to 01:15 PM)', None, 'Asleep 29 Minuten (04:54 PM to 05:23 PM)', None, 'Asleep 4 Stunden, 49 Minuten (08:10 PM to 11:59 PM)']}
last_end_time datetime.datetime(2020, 10, 24, 17, 23, tzinfo=<DstTzInfo 'Europe/Berlin' CEST+2:00:00 DST>)
start_date '2020-10-24'
start_time datetime.datetime(2020, 10, 24, 20, 10, tzinfo=<DstTzInfo 'Europe/Berlin' CEST+2:00:00 DST>)
times {'2020-10-24': [460.0, 110.0, 144.0, 81.0, 219.0, 29.0, 167.0, 289.0]}
yesterday '2020-10-23'
@cdubz
Copy link
Member

cdubz commented May 3, 2021

Looks like a regression caused by e6838a0 (for #198). That sleep pattern code is unfortunately pretty messy and tough to maintain. I'll take a look when I can.

@cdubz cdubz added the bug Reports of unexpected problems or errors label May 3, 2021
@cdubz cdubz added this to the v1.5.2 milestone May 3, 2021
@cdubz cdubz modified the milestones: v1.6.0, v1.6.1 May 14, 2021
@cdubz cdubz modified the milestones: v1.6.1, v1.8.0, v1.7.0 Jun 19, 2021
@BenjaminHae
Copy link
Contributor Author

I've "fixed" it.

We started tracking sleep on the day daylight saving time ended. I've remove all entries of that day, now sleep pattern works as expected.

@cdubz
Copy link
Member

cdubz commented Jul 2, 2021

Glad you were able to work it out. Sorry that I haven't a chance to dig in on this yet. At this rate I'll be to the DST change before I really look at it 😭

@cdubz cdubz modified the milestones: v1.7.0, v1.7.1 Jul 8, 2021
@cdubz cdubz modified the milestones: v1.8.1, v1.8.2, v1.8.3 Aug 5, 2021
@cdubz cdubz removed this from the v1.8.3 milestone Aug 28, 2021
@cdubz
Copy link
Member

cdubz commented Dec 18, 2021

Closing in favor of #174.

@cdubz cdubz closed this as completed Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reports of unexpected problems or errors
Projects
None yet
Development

No branches or pull requests

2 participants