Skip to content

Commit

Permalink
Add some debug information if we encounter is_this_a_valid_booking_ti…
Browse files Browse the repository at this point in the history
…me returning False.
  • Loading branch information
MelissaAutumn committed Nov 5, 2024
1 parent 584adf9 commit 9ed70d0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions backend/src/appointment/exceptions/misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class UnexpectedBehaviourWarning(RuntimeWarning):
def __init__(self, message: str, info: dict):
self.message = message
self.info = info
28 changes: 27 additions & 1 deletion backend/src/appointment/routes/schedule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sentry_sdk
from fastapi import APIRouter, Depends, BackgroundTasks, Request
import logging
import os
Expand Down Expand Up @@ -32,6 +33,7 @@
from ..dependencies.zoom import get_zoom_client
from ..exceptions import validation
from ..exceptions.calendar import EventNotCreatedException
from ..exceptions.misc import UnexpectedBehaviourWarning
from ..exceptions.validation import RemoteCalendarConnectionError, EventCouldNotBeAccepted
from ..tasks.emails import (
send_pending_email,
Expand Down Expand Up @@ -69,9 +71,11 @@ def is_this_a_valid_booking_time(schedule: models.Schedule, booking_slot: schema
# If our end time is below start time, then it's the next day.
add_day = 1 if schedule.end_time <= schedule.start_time else 0

booking_slot_end = booking_slot.start + timedelta(minutes=schedule.slot_duration)

if (
booking_slot.start < datetime.combine(today, schedule.start_time, tzinfo=timezone.utc)
or (booking_slot.start + timedelta(minutes=schedule.slot_duration)) > datetime.combine(today, schedule.end_time, tzinfo=timezone.utc) + timedelta(days=add_day)
or booking_slot_end > datetime.combine(today, schedule.end_time, tzinfo=timezone.utc) + timedelta(days=add_day)
):
return False

Expand Down Expand Up @@ -248,6 +252,28 @@ def request_schedule_availability_slot(

# Ensure the request is valid
if not is_this_a_valid_booking_time(schedule, s_a.slot):
# Gather the relevant information for debugging, and capture it.
debug_obj = {
'schedule': {
'time_updated': schedule.time_updated,
'start': schedule.start_time,
'end': schedule.end_time,
'local_start': schedule.start_time_local,
'local_end': schedule.end_time_local,
'weekdays': schedule.weekdays,
'slot_duration': schedule.slot_duration,
'start_date': schedule.start_date,
'end_date': schedule.end_date,
'earliest_booking': schedule.earliest_booking,
'farthest_booking': schedule.farthest_booking
},
'slot': s_a.slot,
'submitter_timezone': s_a.attendee.timezone,
'owner_timezone': subscriber.timezone,
}
debug_exc = UnexpectedBehaviourWarning(message='Invalid booking time warning!', info=debug_obj)
sentry_sdk.capture_exception(debug_exc)

raise validation.SlotNotFoundException()

# check if slot still available, might already be taken at this time
Expand Down

0 comments on commit 9ed70d0

Please sign in to comment.