FAQ | This is a LIVE service | Changelog

Commit 1fa3878b authored by Monty Dawson's avatar Monty Dawson
Browse files

Ensure we have duplicates before revoking

parent 3de840d0
......@@ -68,12 +68,16 @@ def revoke_duplicate_issued_cards_for_cam_uid(connection: Connection, cam_uid: s
# We want to revoke all but the card with the highest issue_number or card_id, so
# we create a list of card_ids sorted by issue_number and card_id and then split out
# the last element.
card_ids_to_revoke = [
duplicate_card_ids = [
for card in sorted(issued_cards_for_cardholder, key=lambda card: (
card['issue_number'], card['card_id']
if len(duplicate_card_ids) < 2:
raise ValueError(f'Could not find duplicate cards for cardholder {cam_uid}')
card_ids_to_revoke = duplicate_card_ids[:-1]
for card_id in card_ids_to_revoke:
cursor = connection.cursor()
cursor.execute(REVOKE_CARD_AS_DUPLICATE, card_id=card_id)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment