Skip to content

Commit

Permalink
#658 - ensure rowcount is not empty (#688)
Browse files Browse the repository at this point in the history
* #658 - ensure rowcount is not empty

* #658 - base on review comments

* #658 - fix codacy issues

* #658 - add id to logging
  • Loading branch information
ahsanbagwan authored Jan 4, 2021
1 parent bab13c2 commit 2621783
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/rating_service/rating_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ async def _persist_rating_changes(
scoreTime=func.now(),
)
)
await conn.execute(gps_update_sql)
result = await conn.execute(gps_update_sql)

if not result.rowcount:
self._logger.warning("gps_update_sql resultset is empty for game_id %i", game_id)
return

rating_type_id = self._rating_type_ids[rating_type]

Expand Down
15 changes: 15 additions & 0 deletions tests/unit_tests/test_rating_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,18 @@ async def test_game_rating_error_handled(rating_service, game_info, bad_game_inf
service._logger.warning.assert_called()
# second game: results have been saved.
service._persist_rating_changes.assert_called_once()


async def test_game_update_empty_resultset(rating_service):
service = rating_service
game_id = 2
player_id = 1
rating_type = RatingType.GLOBAL
old_ratings = {player_id: Rating(1000, 500)}
after_mean = 1234
new_ratings = {player_id: Rating(after_mean, 400)}
outcomes = {player_id: GameOutcome.VICTORY}

await service._persist_rating_changes(
game_id, rating_type, old_ratings, new_ratings, outcomes
)

0 comments on commit 2621783

Please sign in to comment.