Skip to content
Snippets Groups Projects
Unverified Commit fa5f5cbc authored by Erik Johnston's avatar Erik Johnston Committed by GitHub
Browse files

Fix error handling during insertion of client IPs (#9051)

You can't continue using a transaction once an exception has been
raised, so catching and dropping the error here is pointless and just
causes more errors.
parent 195adf40
No related branches found
No related tags found
No related merge requests found
Fix error handling during insertion of client IPs into the database.
...@@ -470,43 +470,35 @@ class ClientIpStore(ClientIpWorkerStore): ...@@ -470,43 +470,35 @@ class ClientIpStore(ClientIpWorkerStore):
for entry in to_update.items(): for entry in to_update.items():
(user_id, access_token, ip), (user_agent, device_id, last_seen) = entry (user_id, access_token, ip), (user_agent, device_id, last_seen) = entry
try: self.db_pool.simple_upsert_txn(
self.db_pool.simple_upsert_txn( txn,
table="user_ips",
keyvalues={"user_id": user_id, "access_token": access_token, "ip": ip},
values={
"user_agent": user_agent,
"device_id": device_id,
"last_seen": last_seen,
},
lock=False,
)
# Technically an access token might not be associated with
# a device so we need to check.
if device_id:
# this is always an update rather than an upsert: the row should
# already exist, and if it doesn't, that may be because it has been
# deleted, and we don't want to re-create it.
self.db_pool.simple_update_txn(
txn, txn,
table="user_ips", table="devices",
keyvalues={ keyvalues={"user_id": user_id, "device_id": device_id},
"user_id": user_id, updatevalues={
"access_token": access_token,
"ip": ip,
},
values={
"user_agent": user_agent, "user_agent": user_agent,
"device_id": device_id,
"last_seen": last_seen, "last_seen": last_seen,
"ip": ip,
}, },
lock=False,
) )
# Technically an access token might not be associated with
# a device so we need to check.
if device_id:
# this is always an update rather than an upsert: the row should
# already exist, and if it doesn't, that may be because it has been
# deleted, and we don't want to re-create it.
self.db_pool.simple_update_txn(
txn,
table="devices",
keyvalues={"user_id": user_id, "device_id": device_id},
updatevalues={
"user_agent": user_agent,
"last_seen": last_seen,
"ip": ip,
},
)
except Exception as e:
# Failed to upsert, log and continue
logger.error("Failed to insert client IP %r: %r", entry, e)
async def get_last_client_ip_by_device( async def get_last_client_ip_by_device(
self, user_id: str, device_id: Optional[str] self, user_id: str, device_id: Optional[str]
) -> Dict[Tuple[str, str], dict]: ) -> Dict[Tuple[str, str], dict]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment