Skip to content

Éligibilité : Correction de la durée de validité de la certification des critères - #6126

Merged
francoisfreitag merged 2 commits into
masterfrom
ff/considered-certified
May 20, 2025
Merged

Éligibilité : Correction de la durée de validité de la certification des critères#6126
francoisfreitag merged 2 commits into
masterfrom
ff/considered-certified

Conversation

@francoisfreitag

Copy link
Copy Markdown
Member

🤔 Pourquoi ?

Au départ, l’API particulier donnait une période d’éligibilité pour la certification des critères. Il s’est avéré que la réponse de l’API correspond à la question « est-ce que cette personne est bénéficiaire aujourd’hui ? », et que la date de début correspond à l’ouverture des droits actuels. La date de fin s’est révélée fausse et a été changée pour ne jamais être spécifiée par l’API (voir 9d44cd1).

Nous avons décidé de fixer la date de fin à 92 jours, qui correspond à la fin d’acceptabilité d’un justificatif daté (justificatif de moins de trois mois). La période de certification inclut donc maintenant le délai de trois mois (is_considered_valid), mais nous ne sommes pas revenus sur with_is_considered_valid, qui octroie également ce délai. Ainsi, le délai de 92 jours est octroyé deux fois, soit un total de 184 jours au lieu des 92 jours attendus.

🍰 Comment ?

Retrait de l’annotation en base de données qui empêchait de profiter des données préchargées (prefetch_related).

🏝️ Comment tester ?

  1. Créer un SelectedAdministrativeCriteria(certified=True, …) avec une période de certification se terminant il y a 150 jours (~5 mois).
  2. Vérifier que le critère n’apparaît plus comme certifié, par exemple lors du parcours d’embauche.

@francoisfreitag francoisfreitag added the modifié Modifié dans le changelog. label May 13, 2025
@francoisfreitag francoisfreitag self-assigned this May 13, 2025
Comment thread tests/eligibility/test_utils.py Outdated

@celine-m-s celine-m-s 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.

C'est tout bon pour moi mais j'aurais bien attendu le retour de Zohra pour avoir son avis.

@francoisfreitag

Copy link
Copy Markdown
Member Author

On peut attendre lundi prochain, pas d’urgence, le bug est là depuis plusieurs mois et n’affectera pas beaucoup plus d’utilisateurs.

@francoisfreitag
francoisfreitag force-pushed the ff/considered-certified branch 2 times, most recently from 67c20ae to a270a02 Compare May 13, 2025 15:04
Comment thread itou/eligibility/utils.py Outdated
Comment on lines +28 to +33
if hiring_start_at and criterion.certified:
validity_period = InclusiveDateRange(
hiring_start_at - datetime.timedelta(days=criterion.CERTIFICATION_GRACE_PERIOD_DAYS),
hiring_start_at,
)
criterion.is_considered_certified = _inclusive_overlap(validity_period, criterion.certification_period)

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.

Pourquoi créer une InclusiveDateRange et pas juste tester que hiring_start_at est dans le range de certification_period ? Je crois que ça fait pareil et que c'est plus simple, non ? 🤔

Ce qui d'ailleurs me fait me demander si il faudrait pas que ça soit une méthode sur le modèle ? Et éventuellement faire un template filter pour les templates plutôt qu'ajouter un attribut.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pourquoi créer une InclusiveDateRange et pas juste tester que hiring_start_at est dans le range de certification_period ? Je crois que ça fait pareil et que c'est plus simple, non ? 🤔

L’idée était de porter à parité dans le premier commit en virant la requête SQL en trop (et donc en gardant le bug de double durée de certification de is_considered_certified), puis de dégager le bug en utilisant contains dans le second commit.

Ce qui d'ailleurs me fait me demander si il faudrait pas que ça soit une méthode sur le modèle ? Et éventuellement faire un template filter pour les templates plutôt qu'ajouter un attribut.

Le problème est qu’il faut passer la hiring_start_at, et que c’est pénible à faire dans les templates. Je trouve un peu dommage d’injecter les données incomplètes (hiring_start_at, eligibility_diagnosis) pour finir par appeler du Python via un template filter custom qui ne sert que dans ce cas. Il me semble plus lisible, facile à maintenir, etc de formatter les données en Python dans les vues, pour que le template puisse simplement itérer et présenter.

francoisfreitag added a commit that referenced this pull request May 14, 2025
The computation of certification expiry was incorrect, a criteria was
considered valid much longer than intended. This bug hasn’t surfaced to
employers though, because the eligibility diagnosis validity period has
been adjusted to match the certification period, so the diagnosis
expired even though the certification was still valid.

This commit adds a test to confirm employers did not see the certified
badge.

Refs #6126
francoisfreitag added a commit that referenced this pull request May 14, 2025
The computation of certification expiry was incorrect, a criteria was
considered valid much longer than intended. This bug hasn’t surfaced to
employers though, because the eligibility diagnosis validity period has
been adjusted to match the certification period, so the diagnosis
expired even though the certification was still valid.

This commit adds a test to confirm employers did not see the certified
badge.

Refs #6126
github-merge-queue Bot pushed a commit that referenced this pull request May 15, 2025
The computation of certification expiry was incorrect, a criteria was
considered valid much longer than intended. This bug hasn’t surfaced to
employers though, because the eligibility diagnosis validity period has
been adjusted to match the certification period, so the diagnosis
expired even though the certification was still valid.

This commit adds a test to confirm employers did not see the certified
badge.

Refs #6126
Instead of instructing the database to annotate whether the diagnosis is
considered valid, compute that in Python. The database does not provide
additional value, and calling `.annotate(is_considered_certified=…)`
invalidates the prefetched administrative criteria.
Originally, the API particulier provided a start date and an end date
(computed as the current date + 3 months). It was updated to always
return None for the end date field, to better indicate that the end date
is not known without breaking existing integrations.

The certification period was updated to follow the API changes with
9d44cd1, where the end date is now
computed to 92 days after the certification date, as the API only
answers the question “is that person a beneficiary today?”. The 92 days
come from our purpose for certification: it’s the 3-month limit to
justify access to the RSA.

However, we did not go back to `is_considered_certified`, which also
grants the 92 days grace period, resulting in an 184 days grace period.
@francoisfreitag
francoisfreitag force-pushed the ff/considered-certified branch from a270a02 to b7057f1 Compare May 20, 2025 15:02
@francoisfreitag
francoisfreitag enabled auto-merge May 20, 2025 15:03
@francoisfreitag
francoisfreitag added this pull request to the merge queue May 20, 2025
Merged via the queue into master with commit 21c1c00 May 20, 2025
@francoisfreitag
francoisfreitag deleted the ff/considered-certified branch May 20, 2025 15:18
@sentry

sentry Bot commented May 21, 2025

Copy link
Copy Markdown

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ TypeError: argument of type 'NoneType' is not iterable /employees/detail/{public_id} View Issue

Did you find this useful? React with a 👍 or 👎

dejafait pushed a commit that referenced this pull request Jul 15, 2025
The computation of certification expiry was incorrect, a criteria was
considered valid much longer than intended. This bug hasn’t surfaced to
employers though, because the eligibility diagnosis validity period has
been adjusted to match the certification period, so the diagnosis
expired even though the certification was still valid.

This commit adds a test to confirm employers did not see the certified
badge.

Refs #6126
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug modifié Modifié dans le changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants