Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demandeur d’emploi : Correction de la sélection de la commune de naissance pour les personnes nées le dernier jour de validité de la commune #5227

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

rsebille
Copy link
Contributor

@rsebille rsebille commented Dec 9, 2024

🤔 Pourquoi ?

Test bagottant : https://github.com/gip-inclusion/les-emplois/actions/runs/12235030153/attempts/1
Reproductible avec pytest --randomly-seed=3864335593 -vv tests/www/employee_record_views/test_create.py::TestCreateEmployeeRecordStep2::test_access_granted

Les valeurs choisies était "1999-12-31" pour la date de naissance alors que la ville était :

  id   | start_date |  end_date  | code  |     name     |          created_at           | city_id 
-------+------------+------------+-------+--------------+-------------------------------+---------
 57089 | 1900-01-01 | 1999-12-31 | 67152 | GEISPOLSHEIM | 2023-10-02 08:19:11.118299+00 |  [NULL]

@rsebille rsebille added the no-changelog Ne doit pas figurer dans le journal des changements. label Dec 9, 2024
@rsebille rsebille self-assigned this Dec 9, 2024
Copy link
Contributor

@francoisfreitag francoisfreitag left a comment

Choose a reason for hiding this comment

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

❤️

@@ -371,7 +371,7 @@ def by_insee_code_and_period(self, insee_code, period):
"Lookup a Commune object by INSEE code and valid at the given period"
return (
self.filter(code=insee_code, start_date__lte=period)
.filter(Q(end_date=None) | Q(end_date__gt=period))
Copy link
Contributor

Choose a reason for hiding this comment

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

À quand l’utilisation de InclusiveDateRange ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Un jour. Peut-être. 😁


result = Commune.objects.by_insee_code_and_period(99999, datetime.datetime(2022, 11, 28))
assert new_commune == result
for period in [new_commune.start_date, datetime.date(2022, 11, 28), timezone.now()]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for period in [new_commune.start_date, datetime.date(2022, 11, 28), timezone.now()]:
for period in [new_commune.start_date, datetime.date(2022, 11, 28), timezone.localdate()]:

@rsebille rsebille force-pushed the rsebille/er-flaky-test branch 2 times, most recently from d4b2993 to 89478a6 Compare December 10, 2024 11:33
Copy link
Contributor Author

@rsebille rsebille left a comment

Choose a reason for hiding this comment

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

@francoisfreitag La correction pour le test en échec au moment de ta relecture est assez velue donc je veux bien un zieutage pour être sûr que c'est compréhensible :).

@@ -371,7 +371,7 @@ def by_insee_code_and_period(self, insee_code, period):
"Lookup a Commune object by INSEE code and valid at the given period"
return (
self.filter(code=insee_code, start_date__lte=period)
.filter(Q(end_date=None) | Q(end_date__gt=period))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Un jour. Peut-être. 😁

@francoisfreitag
Copy link
Contributor

Je n’étais pas satisfait par ta proposition, je viens de pousser un fixup pour clarifier. Effectivement c’est velu.

@francoisfreitag
Copy link
Contributor

Romain, je te laisse merger si ça te convient ?

@xavfernandez
Copy link
Contributor

Ça mériterait peut-être un changelog au final: https://itou-inclusion.slack.com/archives/C01181Y04LT/p1733996418452109 🙈

tests/www/apply/test_process.py Outdated Show resolved Hide resolved
tests/www/apply/test_process.py Outdated Show resolved Hide resolved
@rsebille rsebille changed the title Tech : Corrections liés au lieu de naissance Demandeur d’emploi : Correction de la sélection de la commune de naissance pour les personnes nées le dernier jours de celle-ci Dec 12, 2024
@rsebille rsebille added modifié and removed no-changelog Ne doit pas figurer dans le journal des changements. labels Dec 12, 2024
@francoisfreitag francoisfreitag changed the title Demandeur d’emploi : Correction de la sélection de la commune de naissance pour les personnes nées le dernier jours de celle-ci Demandeur d’emploi : Correction de la sélection de la commune de naissance pour les personnes nées le dernier jour de validité de la commune Dec 12, 2024
@francoisfreitag
Copy link
Contributor

J’ai l’impression qu’on s’est télescopé ?

@rsebille
Copy link
Contributor Author

J’ai l’impression qu’on s’est télescopé ?

Je pense pas, j'ai rien push en tout cas.
Mais j'ai pas compris pourquoi il a vu autant de commit différent par contre 🤷

@francoisfreitag
Copy link
Contributor

C’est moi qui utilisait une remote pas à jour dont la branche master avait déviée.

@francoisfreitag francoisfreitag added this pull request to the merge queue Dec 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 12, 2024
@@ -371,29 +371,3 @@ def test_submit_valid(self):
data=form_data, birthdate=valid_birthdate, with_birthdate_field=False
)
assert form.is_valid()

def test_submit_commune_invalid_commune_lookup(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Ce test avait le même problème et c’est un doublon moins bien intégré de test_accept_updated_birthdate_invalidating_birth_place. => 🗑️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Je préférerais presque garder celui-ci et virer sa logique de l'autre mais oui 1 seul est suffisant ;).

Copy link
Contributor

Choose a reason for hiding this comment

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

Je préfère garder les tests d’intégration, qui couvrent mieux la façon dont les données arrivent au formulaire et limitent le risque de couvrir des cas impossible en réalité. 🤷

rsebille and others added 3 commits December 12, 2024 16:25
 code  | start_date |  end_date
-------+------------+------------
 01001 | 1900-01-01 | 1999-12-31
 01001 | 2000-01-01 | [NULL]
The content is already verified in the accept views integration, and
getting the data right is tricky:

```
birth_place = (
    Commune.objects.filter(
        # The birthdate must be >= 1900-01-01, and we’re removing 1 day from start_date.
        Q(start_date__gt=datetime.date(1900, 1, 2)),
        # Must be a valid choice for the user current birthdate.
        Q(start_date__lte=birthdate),
        Q(end_date__gte=birthdate) | Q(end_date=None),
    )
    .exclude(
        Exists(
            # The same code must not exists at the early_date.
            Commune.objects.exclude(pk=OuterRef("pk")).filter(
                code=OuterRef("code"),
                start_date__lt=OuterRef("start_date"),
            )
        )
    )
    .first()
)
```
@rsebille rsebille force-pushed the rsebille/er-flaky-test branch from 5a4e6af to 5d85773 Compare December 12, 2024 15:26
@rsebille rsebille enabled auto-merge December 12, 2024 15:26
@rsebille rsebille added this pull request to the merge queue Dec 12, 2024
Merged via the queue into master with commit 6adb772 Dec 12, 2024
9 checks passed
@rsebille rsebille deleted the rsebille/er-flaky-test branch December 12, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants