Skip to content

Commit b61bb7c

Browse files
rantamatti-lamppu
authored andcommitted
Fix ReservationUnits in common hierarchy by Resource but unrelated Space
- This bug was discovered in manual testing.
1 parent b6d5828 commit b61bb7c

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

reservations/querysets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ def get_affecting_reservations_as_closed_time_spans(
121121
# Get the full family of the space.
122122
family: set[SpacePK] = space_to_family.get(space_id)
123123

124+
# Space is not related in common hierarchy with any of the reservation units, skip it.
125+
if family is None:
126+
continue
127+
124128
for reservation_unit_info in reservation_unit_infos:
125129
# If any space from the family is a direct space on the reservation unit,
126130
# add a timespan from the reservation to the reservation unit, but only once.

tests/test_graphql_api/test_reservation_unit/test_query_reservable_fields.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,58 @@ def test__query_reservation_unit_reservable__reservations__in_common_hierarchy__
10691069
}
10701070

10711071

1072+
@freezegun.freeze_time(NOW)
1073+
def test__query_reservation_unit_reservable__reservations__in_common_hierarchy__by_resource__additional_filters(
1074+
graphql, reservation_unit
1075+
):
1076+
"""
1077+
This is a regression test for a bug that was found during manual testing.
1078+
Simply recreate the exact scenario instead of using the above test cases.
1079+
1080+
The error occurred when the ReservationUnit GQL query had additional filters that filtered out ReservationUnits
1081+
which were related in common hierarchy by Resource and had a Space which was not related in common hierarcy.
1082+
"""
1083+
common_resource = ResourceFactory()
1084+
reservation_unit_2: ReservationUnit = ReservationUnitFactory.create(
1085+
resources=[common_resource],
1086+
spaces=[SpaceFactory()],
1087+
origin_hauki_resource=reservation_unit.origin_hauki_resource,
1088+
)
1089+
reservation_unit.resources.set([common_resource])
1090+
reservation_unit.spaces.set([SpaceFactory()])
1091+
reservation_unit.save()
1092+
1093+
# 2023-05-20 10:00 - 12:00 (2h)
1094+
ReservationFactory.create(
1095+
begin=_datetime(day=20, hour=10),
1096+
end=_datetime(day=20, hour=12),
1097+
reservation_unit=[reservation_unit_2],
1098+
state=ReservationStateChoice.CREATED,
1099+
)
1100+
1101+
# 2023-05-20 10:00 - 12:00 (2h)
1102+
ReservableTimeSpanFactory.create(
1103+
resource=reservation_unit.origin_hauki_resource,
1104+
start_datetime=_datetime(day=20, hour=10),
1105+
end_datetime=_datetime(day=20, hour=12),
1106+
)
1107+
1108+
response = graphql(
1109+
reservation_units_reservable_query(
1110+
pk=reservation_unit.pk,
1111+
fields="pk isClosed firstReservableDatetime",
1112+
)
1113+
)
1114+
1115+
assert response.has_errors is False, response
1116+
assert len(response.edges) == 1, response
1117+
assert response.node(0) == {
1118+
"pk": reservation_unit.pk,
1119+
"isClosed": False,
1120+
"firstReservableDatetime": None,
1121+
}
1122+
1123+
10721124
########################################################################################################################
10731125

10741126

0 commit comments

Comments
 (0)