Skip to content

Tech: deleguer le casting referentiel aux PrefillTypeDeChamp#13490

Merged
mfo merged 5 commits into
demarche-numerique:mainfrom
mfo:prefill-referentiel-compat
Jul 17, 2026
Merged

Tech: deleguer le casting referentiel aux PrefillTypeDeChamp#13490
mfo merged 5 commits into
demarche-numerique:mainfrom
mfo:prefill-referentiel-compat

Conversation

@mfo

@mfo mfo commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Probleme

ReferentielChamp#call_caster dupliquait la logique de normalisation et validation que les PrefillTypeDeChamp gerent deja pour le prefill URL : conversion de dates, formatting de nombres, validation d'options dropdown, normalisation de civilite, etc. Deux chemins de code distincts pour le meme objectif (caster une valeur brute vers un champ).

Solution

Enrichir les PrefillTypeDeChamp pour accepter les memes inputs que les APIs referentiel, puis deleguer update_prefillable_champ a PrefillTypeDeChamp#to_assignable_attributes au lieu de call_caster.

Enrichissements prefill :

  • PrefillCiviliteTypeDeChamp : fuzzy matching ("monsieur", "male", "femme", etc.)
  • PrefillDateTypeDeChamp : timestamps unix (Integer, Float, String) pour date et datetime
  • PrefillNumberTypeDeChamp : tronquer les Float en Integer pour integer_number

Swap : update_prefillable_champ delegue a PrefillTypeDeChamp.build(tdc, revision).to_assignable_attributes(champ, value) avec une pre-normalisation normalize_api_value pour le cas drop_down_list + Array.

Cleanup : call_caster renomme en cast_display_value, reduit de 17 a 7 branches (seuls les types d'affichage JSONB restent).

Changements de comportement

  • decimal_number avec input entier : stocke "2" au lieu de "2.0"
  • multiple_drop_down_list : rejette les valeurs hors options (screening au lieu de validation ulterieure)
  • address : set value + external_id (la resolution BAN ecrase value ensuite)

Generated with Claude Code

mfo and others added 5 commits July 17, 2026 15:44
Accept textual variants ("monsieur", "m", "male", "homme",
"mademoiselle", "female", "femme", etc.) and normalize them
to the canonical "M." / "Mme" values — matching the behavior
of ReferentielChamp#call_caster.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PrefillDateTypeDeChamp now handles Numeric values (Integer and
Float unix timestamps) and string-encoded timestamps alongside
regular date strings — matching the behavior of
ReferentielChamp#call_caster.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PrefillNumberTypeDeChamp now truncates Float values to Integer
for integer_number fields (e.g. 42.2 → "42") — matching the
behavior of ReferentielChamp#call_caster. Also documents that
Integer values already work for decimal_number fields.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace cast_value_for_type_de_champ with delegation to
PrefillTypeDeChamp#to_assignable_attributes, so referentiel and
URL prefill share the same normalization and validation logic.

call_caster is kept for cast_displayable_values (display-only
types like :boolean, :array, :string).

Behavior changes:
- decimal_number with integer input stores "2" instead of "2.0"
- multiple_drop_down_list rejects values not in options
- address prefill now sets value alongside external_id

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Now that champ prefill delegates to PrefillTypeDeChamp, the old
call_caster only serves cast_displayable_values. Remove the 10
dead champ-type branches (drop_down_list, multiple_drop_down_list,
checkbox, yes_no, text, textarea, etc.) and rename to
cast_display_value to reflect its sole purpose.

The 7 remaining branches match the display types defined in
Referentiels::MappingFormComponent::TYPES.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mfo
mfo force-pushed the prefill-referentiel-compat branch from b4c0788 to f295459 Compare July 17, 2026 13:44
@mfo
mfo added this pull request to the merge queue Jul 17, 2026
Merged via the queue into demarche-numerique:main with commit 4e3429e Jul 17, 2026
32 of 33 checks passed
@mfo
mfo deleted the prefill-referentiel-compat branch July 17, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants