Skip to content
This repository was archived by the owner on May 4, 2021. It is now read-only.

Commit 2cd9400

Browse files
committed
Fixed bug and code coverage due to SQLAlchemy returning UUID objects vs strings
1 parent c0fa035 commit 2cd9400

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

sparfa_server/biglearn/clients.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from logging import getLogger
2-
from json import dumps
32
from requests import Session
43

54
from .. import __version__

sparfa_server/tasks/calcs.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,19 @@ def calculate_exercises():
148148
)
149149

150150
response_dicts_by_calculation_uuid = defaultdict(list)
151+
# Beware that uuid columns return UUID objects (not strings) when using from_statement()
151152
for result in session.query('calculation_uuid', Response).from_statement(text(dedent("""
152153
SELECT "values"."calculation_uuid", "responses".*
153154
FROM "responses" INNER JOIN (VALUES {}) AS "values"
154155
("calculation_uuid", "ecosystem_uuid", "student_uuid")
155156
ON "responses"."student_uuid" = "values"."student_uuid"
156157
AND "responses"."ecosystem_uuid" = "values"."ecosystem_uuid"
157158
""".format(', '.join(calculation_values))).strip())).all():
158-
calc_uuid = result.calculation_uuid
159+
calc_uuid = str(result.calculation_uuid)
159160
response = result.Response
160-
if response.exercise_uuid in known_exercise_uuids_by_calculation_uuid[calc_uuid]:
161+
if str(
162+
response.exercise_uuid
163+
) in known_exercise_uuids_by_calculation_uuid[calc_uuid]:
161164
response_dicts_by_calculation_uuid[calc_uuid].append(response.dict_for_algs)
162165

163166
exercise_calculation_requests = []

tests/unit/tasks/test_calcs.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111

1212
def test_calculate_ecosystem_matrices(transaction):
13-
ecosystem_1 = Ecosystem(uuid=str(uuid4()), metadata_sequence_number=0, sequence_number=1)
13+
ecosystem_1 = Ecosystem(
14+
uuid=str(uuid4()),
15+
metadata_sequence_number=0,
16+
sequence_number=1,
17+
last_ecosystem_matrix_update_calculation_uuid=str(uuid4())
18+
)
1419

1520
calculation_uuid = str(uuid4())
1621
ecosystem_matrix_updates = [{

0 commit comments

Comments
 (0)