Skip to content

[Certification] Certifier de manière asynchrone via un feature flag - #6644

Merged
celine-m-s merged 3 commits into
masterfrom
celinems/certify_async_only
Jul 31, 2025
Merged

celine-m-s merged 3 commits into
masterfrom
celinems/certify_async_only

Conversation

@celine-m-s

@celine-m-s celine-m-s commented Jul 30, 2025 •

Copy link
Copy Markdown
Contributor

🤔 Pourquoi ?

Avec l'arrivée de la certification RQTH, 3 nouvelles requêtes seront exécutées dans la méthode certify_criteria si le critère TH est sélectionné. Ces appels risquent d'allonger la durée de la requête pour l'utilisateur final qui devra simplement attendre que toutes les API aient rendu leur verdict.

Il y a néanmoins un désavantage : si le critère est en cours de certification, le badge affichera « Critère non certifié » car c'est le fonctionnement actuel. Une PR suivra pour proposer d'autres intitulés.

🍰 Comment ?

Rendre l'appel asynchrone par défaut et mettre en place un feature flag pour revenir rapidement en arrière si les utilisateurs sont perdus.

🚨 À vérifier

  • Mettre à jour le CHANGELOG_breaking_changes.md ?
  • Ajouter l'étiquette « Bug » ?

@celine-m-s celine-m-s added the modifié Modifié dans le changelog. label Jul 30, 2025
@celine-m-s celine-m-s self-assigned this Jul 30, 2025
Comment thread tests/eligibility/test_iae.py Outdated
assert not criterion.is_certifiable


@pytest.mark.parametrize("certify_criteria_async_only", [True, False])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je pense qu'on peut se permettre de ne pas tester les 6 combinaisons des 2 parametrizes suivants en synchrone et en asynchrone.

Je verrais plutôt un test séparé qui vérifie que :
En mode synchrone, on appelle itou.eligibility.tasks.certify_criteria En mode synchrone aussi, si ça fail, on appelle itou.eligibility.tasks.async_certify_criteriaEn mode asynchrone on appelle directementitou.eligibility.tasks.async_certify_criteriaJe pense que les 2 premières parties existent déjà donc il faut peut être juste ajouter le 3e cas dans un nouveau test.

@celine-m-s
celine-m-s requested a review from tonial July 31, 2025 12:29

@tonial tonial left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯



@pytest.mark.parametrize(
"async_mode_only, certify_criteria_called, async_certify_criteria_called, side_effect",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super classe !

Comment thread tests/eligibility/test_iae.py Resolved
Comment thread tests/eligibility/test_iae.py Resolved
Comment thread tests/eligibility/test_iae.py Resolved
Comment thread tests/www/apply/test_process.py Outdated

@freeze_time("2024-09-11")
def test_accept_personal_data_readonly_with_certified_criteria(self, client):
@respx.mock()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besoin de ces @respx.mock() (ici et les tests suivants, de ce fichier et de l'autre) ?
J'ai l'impression que tu as fini par mocker itou.utils.apis.api_particulier._request systématiquement ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mon cerveau est fatigué mais je n'arrive pas à faire le lien entre ajouter ce if et le besoin de mocker dans les tests, ça devrais rien changer normalement, non ? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besoin de ces @respx.mock() (ici et les tests suivants, de ce fichier et de l'autre) ?
J'ai l'impression que tu as fini par mocker itou.utils.apis.api_particulier._request systématiquement ?

En effet. Merci !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mon cerveau est fatigué mais je n'arrive pas à faire le lien entre ajouter ce if et le besoin de mocker dans les tests, ça devrais rien changer normalement, non ? 🤔

🤔 En effet... Hier, ça me paraissait très logique mais je ne me souviens plus pourquoi. J'aurais dû laisser un commentaire ou l'expliquer dans le commit. Je creuse.

@celine-m-s celine-m-s Jul 31, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ça y est, je me souviens.
Afin de tester qu'on testait bien l'asynchrone et le synchrone, j'ai successivement activé et désactivé certify_criteria et async_certify_criteria dans le bloc try / except suivant :

    def certify_criteria(self):
        try:
            # Optimistic call to show certified badge in response immediately.
            certify_criteria(self)
        except Exception:  # Do not fail the web request if the criteria could not be certified.
            logger.info("Could not certify criteria synchronously.", exc_info=True)
            async_certify_criteria(self._meta.model_name, self.pk)

Tous les tests passaient avec l'appel asynchrone mais avec l'appel synchrone, les tests que j'ai corrigés échouaient en levant une httpx.ConnectError, ce qui me semble logique car la requête n'est pas mockée.

La tâche asynchrone passe et certifie bien le critère malgré l'absence du mock. J'avoue que je ne comprends pas bien. Je continue de creuser.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'avoue que je ne vois pas.
En soi, je pourrais laisser comme c'était avant, en supprimant ce mock, mais ça ne me semble pas « juste » car un appel est censé être fait pour certifier le critère.
À votre avis ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je crois que j'ai compris, la ConnectError était attrapée dans task.certify_criteria et donc on passait en mode async, ce qui n'était jamais exécuté puisque c'est un on_commit.
Mais en soi ce n'est pas un problème car ces fonctions ne test pas le comportement de certification donc je dirais de laisser comme avant, ça cassera le jour où on changera c'est pas grave, mais au moins pendant ce temps on a pas des lignes qui ne servent pas.

@celine-m-s celine-m-s Jul 31, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je trouve que c'est vraiment bizarre de savoir que l'appel n'a pas lieu, alors qu'il le devrait, et de ne pas l'indiquer quelque part. Mais bon, comme vous voulez.

@celine-m-s
celine-m-s force-pushed the celinems/certify_async_only branch from 45d8d8f to d421819 Compare July 31, 2025 13:33
@celine-m-s
celine-m-s requested a review from xavfernandez July 31, 2025 15:06
@celine-m-s
celine-m-s force-pushed the celinems/certify_async_only branch from 9c7bea0 to 5b92889 Compare July 31, 2025 15:45
… only

If users start questioning about certification results, it will be
faster to switch the feature flag value to go back to the synchronous
certification.
@celine-m-s
celine-m-s force-pushed the celinems/certify_async_only branch from 5b92889 to a2adc09 Compare July 31, 2025 15:47
@celine-m-s

Copy link
Copy Markdown
Contributor Author

@rsebille Retours pris en compte.

Comment thread tests/eligibility/test_iae.py Resolved
return_value=RESPONSES[criteria_kind][ResponseKind.CERTIFIED],
)
job_seeker = JobSeekerFactory(with_address=True, born_in_france=True)
job_seeker = JobSeekerFactory(certifiable=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merci 🙏

@celine-m-s
celine-m-s force-pushed the celinems/certify_async_only branch from a2adc09 to 55809d7 Compare July 31, 2025 21:24
@celine-m-s
celine-m-s enabled auto-merge July 31, 2025 21:26
@celine-m-s

Copy link
Copy Markdown
Contributor Author

@rsebille Si tu passes dans le coin, il y a la PR dans les-emplois-secrets qui attend un petit tampon pour activer le feature flag. :) Merci !

@celine-m-s
celine-m-s added this pull request to the merge queue Jul 31, 2025
Merged via the queue into master with commit 5d27566 Jul 31, 2025
@celine-m-s
celine-m-s deleted the celinems/certify_async_only branch July 31, 2025 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

modifié Modifié dans le changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants