This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
txn
being redefined in for loop as we are iterating over it #10739
Copy link
Copy link
Closed
Labels
S-MinorBlocks non-critical functionality, workarounds exist.Blocks non-critical functionality, workarounds exist.T-DefectBugs, crashes, hangs, security vulnerabilities, or other reported issues.Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Description
Spurred on by the note in #10734 about txn
being redefined in for loop as we are iterating over it.
We were originally iterating over
txn
, which can work, but astxn
was being used to run a
simple_delete operation inside the loop, it was actually being redefined mid-loop.
I was curious if there were other cases in the codebase, so I searched for in txn:
and found one more case. It looks like this would cause a problem if there was an event where the event_auth_chains
-> chain_id
was not defined.
synapse/synapse/storage/databases/main/events.py
Lines 578 to 588 in c586d68
for auth_id, event_type, state_key, chain_id, sequence_number in txn: | |
event_to_types[auth_id] = (event_type, state_key) | |
if chain_id is None: | |
# No chain ID, so the event was persisted out of band. | |
# We add to list of events to calculate auth chains for. | |
events_to_calc_chain_id_for.add(auth_id) | |
event_to_auth_chain[auth_id] = db_pool.simple_select_onecol_txn( | |
txn, |
Linting
Maybe we should disallow iterating over txn
directly in favor of using txn.fetchall()
Metadata
Metadata
Assignees
Labels
S-MinorBlocks non-critical functionality, workarounds exist.Blocks non-critical functionality, workarounds exist.T-DefectBugs, crashes, hangs, security vulnerabilities, or other reported issues.Bugs, crashes, hangs, security vulnerabilities, or other reported issues.