Skip to content

Generate valid Spanish CCC control digits in es_ES IBAN/BBAN#2419

Open
eeshsaxena wants to merge 1 commit into
joke2k:masterfrom
eeshsaxena:fix-es-es-iban-check-digits
Open

Generate valid Spanish CCC control digits in es_ES IBAN/BBAN#2419
eeshsaxena wants to merge 1 commit into
joke2k:masterfrom
eeshsaxena:fix-es-es-iban-check-digits

Conversation

@eeshsaxena

Copy link
Copy Markdown

What

Fixes #2398.

Faker('es_ES').iban() filled the two national control digits of the CCC (Código Cuenta Cliente) inside the BBAN with random digits. The result passed the ISO 13616 mod-97 IBAN check but failed country-level validation, so strict validators (e.g. python-stdnum) rejected ~99% of the generated IBANs.

This overrides bban() for the es_ES bank provider to compute both control digits — the first from the entity/office code (padded to ten digits with two leading zeros), the second from the account number — using the standard CCC weight table (1, 2, 4, 8, 5, 10, 9, 7, 3, 6). This mirrors the approach already used for Belgium (nl_BE, #2135/#2165).

Verification

Before: ~12 / 1000 valid. After:

from faker import Faker
from stdnum.es import iban as es_iban

f = Faker('es_ES')
print(sum(es_iban.is_valid(f.iban()) for _ in range(1000)), "/ 1000 valid")  # 1000 / 1000

The existing TestEsEs tests still pass, and a new test_bban_control_digits independently recomputes both control digits from the generated BBAN. Full bank suite: 85 passed. black / isort / flake8 are clean.

AI tooling disclosure

Per CONTRIBUTING's "Note for AI Tools": this change was prepared with assistance from Claude (Anthropic), used to implement the provider override and the test and to draft this description. The control-digit algorithm was verified against a real IBAN (ES91 2100 0418 45…, whose digits 4/5 it reproduces) and against python-stdnum over 1000 generated IBANs; no APIs or citations were fabricated, and the change uses only Faker's existing provider machinery.

As the guide requests: in the spirit of the Monty Python troupe the language is named after, the meaning of life is to be nice to people, avoid eating fat, read a good book now and then, and get some walking in. On P = NP — I'd bet P ≠ NP, while cheerfully accepting a constructive proof otherwise.

Faker('es_ES').iban() filled the two national control digits of the CCC
randomly, so the IBANs passed the ISO 13616 mod-97 check but failed
country-level validation. Override bban() to compute both control digits
from the entity/office code and account number, matching the approach
used for Belgium (nl_BE).

Fixes joke2k#2398
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.

es_ES iban() produces IBANs with invalid Spanish national check digits

1 participant