Skip to content

Commit 11343aa

Browse files
Ricardoalsodutrieuc
authored andcommitted
[IMP] auth_saml: only lock providers being updated
Fix logic of SELECT FOR UDPDATE to only lock records whose metadata will be updated
1 parent 2c9207b commit 11343aa

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

auth_saml/models/auth_saml_provider.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,21 +411,35 @@ def action_refresh_metadata_from_url(self):
411411
)
412412
if not providers:
413413
return False
414+
415+
providers_to_update = {}
416+
for provider in providers:
417+
document = requests.get(provider.idp_metadata_url, timeout=5)
418+
if document.status_code != 200:
419+
raise UserError(
420+
f"Unable to download the metadata for {provider.name}: {document.reason}"
421+
)
422+
if document.text != provider.idp_metadata:
423+
providers_to_update[provider.id] = document.text
424+
425+
if not providers_to_update:
426+
return False
427+
414428
# lock the records we might update, so that multiple simultaneous login
415429
# attempts will not cause concurrent updates
430+
provider_ids = tuple(providers_to_update.keys())
416431
self.env.cr.execute(
417432
"SELECT id FROM auth_saml_provider WHERE id in %s FOR UPDATE",
418-
(tuple(providers.ids),),
433+
(provider_ids,),
419434
)
420435
updated = False
421436
for provider in providers:
422-
document = requests.get(provider.idp_metadata_url, timeout=5)
423-
if document.status_code != 200:
424-
raise UserError(
425-
f"Unable to download the metadata for {provider.name}: {document.reason}"
437+
if provider.id in providers_to_update:
438+
provider.idp_metadata = providers_to_update[provider.id]
439+
_logger.info(
440+
"Updated metadata for provider %s from %s",
441+
provider.name,
426442
)
427-
if document.text != provider.idp_metadata:
428-
provider.idp_metadata = document.text
429-
_logger.info("Updated provider metadata for %s", provider.name)
430443
updated = True
444+
431445
return updated

0 commit comments

Comments
 (0)