Predict the output
What does decoding the cursor print?
import base64
import json
def encode(created_at: str, row_id: int) -> str:
raw = json.dumps([created_at, row_id]).encode()
return base64.urlsafe_b64encode(raw).decode().rstrip("=")
def decode(token: str) -> tuple[str, int]:
pad = "=" * (-len(token) % 4)
ts, row_id = json.loads(base64.urlsafe_b64decode(token + pad))
return str(ts), int(row_id)
t = encode("2026-10-31T12:00:00Z", 7)
print(decode(t))Hint 1 of 1
Look at decode's return type.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A ('2026-10-31T12:00:00Z', 7)
Correct. The cursor round-trips the last row's sort key and id.
The token is base64url-encoded JSON of the last row's sort key and id. decode puts the stripped padding back, parses the list and converts it to a typed tuple, so the next page starts exactly after that row.
Why not the others?
- B
['2026-10-31T12:00:00Z', 7]. decode returns a tuple, not the raw JSON list. - C A padding error. decode adds the stripped '=' padding back.
- D
('2026-10-31T12:00:00Z', '7'). row_id is converted with int().