Skip to content

Commit 6c55213

Browse files
committed
Fix logic of SELECT FOR UDPDATE to only lock records that will be updated
1 parent ff6c5f1 commit 6c55213

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

auth_saml/models/auth_saml_provider.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -408,21 +408,35 @@ def action_refresh_metadata_from_url(self):
408408
)
409409
if not providers:
410410
return False
411+
412+
providers_to_update = {}
413+
for provider in providers:
414+
document = requests.get(provider.idp_metadata_url, timeout=5)
415+
if document.status_code != 200:
416+
raise UserError(
417+
f"Unable to download the metadata for {provider.name}: {document.reason}"
418+
)
419+
if document.text != provider.idp_metadata:
420+
providers_to_update[provider.id] = document.text
421+
422+
if not providers_to_update:
423+
return False
424+
411425
# lock the records we might update, so that multiple simultaneous login
412426
# attempts will not cause concurrent updates
427+
provider_ids = tuple(providers_to_update.keys())
413428
self.env.cr.execute(
414429
"SELECT id FROM auth_saml_provider WHERE id in %s FOR UPDATE",
415-
(tuple(providers.ids),),
430+
(tuple(provider_ids),),
416431
)
417432
updated = False
418433
for provider in providers:
419-
document = requests.get(provider.idp_metadata_url)
420-
if document.status_code != 200:
421-
raise UserError(
422-
f"Unable to download the metadata for {provider.name}: {document.reason}"
434+
if provider.id in providers_to_update:
435+
provider.idp_metadata = providers_to_update[provider.id]
436+
_logger.info(
437+
"Updated metadata for provider %s from %s",
438+
provider.name,
423439
)
424-
if document.text != provider.idp_metadata:
425-
provider.idp_metadata = document.text
426-
_logger.info("Updated provider metadata for %s", provider.name)
427440
updated = True
441+
428442
return updated

0 commit comments

Comments
 (0)