Update validator to allow new Brazilian CNPJ alphanumeric format#533
Update validator to allow new Brazilian CNPJ alphanumeric format#533rennerocha wants to merge 4 commits intodjango:masterfrom
Conversation
951b9d4 to
83a8213
Compare
In July-2026, alphanumeric CNPJ will be allowed: https://www.gov.br/receitafederal/pt-br/acesso-a-informacao/acoes-e-programas/programas-e-atividades/cnpj-alfanumerico Given that the new format is 100% compatible with the current format, we can update the validators now, making the transition smoother for users of the library.
83a8213 to
e6dc8fc
Compare
|
Hello, @rennerocha |
The task is done. The code updated the validators so everyone will be able to handle the new CNPJ format. I just need that some maintainer of the project review it so it can be in the next release of the project. Based on the commit history of the project, it appears that @benkonrath would be a good person to review it (or at least indicate who could do that) as he is the one with more commits in the latest year. |
|
Thanks for the ping, and sorry for the delay. I'll try to get to it this week. |
|
I see that min_length / max_length args have been removed from the doc string and the tests. Also, a couple of the previously valid values in the tests have been removed. I would expect that only a few additional test cases with the new alphanumeric version of CNPJ. On my first read, this seems like a full re-implementation that's not code-compatible with the the existing version of Perhaps a new field and validator should be added instead? -- maybe using the year in the name e.g. If it is code-compatible, then the tests and doc string shouldn't change so drastically:
|
|
@benkonrath thank you for the review. I addressed some comments and I will answer some considerations:
I added the same valid and invalid values that were present previously to ensure that we don't break anything. The only exception is the format I reintroduced the min/max length to reduce the changes in the current code, although they are not strictly necessary, since values that do not have this minimum or maximum number of characters will not be validated as valid in any way.
In the old implementation, depending on the value you add to Everything else will continue to work, even if the implementation looks different. as the rules for validating CNPJs with digits only are the same using characters. This was done by Receita Federal (our Tax Agency) to avoid breaking things everywhere.
I updated the tests and docstring as you suggested. |
In July-2026, alphanumeric CNPJ will be allowed:
https://www.gov.br/receitafederal/pt-br/acesso-a-informacao/acoes-e-programas/programas-e-atividades/cnpj-alfanumerico
Given that the new format is 100% compatible with the current format, we can update the validators now, making the transition smoother for users of the library.
Thanks for your contribution!
A checklist is included below which helps us keep the code contributions
consistent and helps speed up the review process. You can add additional
commits to your pull request if you haven't met all of these points on your
first version.
All Changes
Add an entry to the docs/changelog.rst describing the change.
Add an entry for your name in the docs/authors.rst file if it's not
already there.
New Fields Only
Prefix the country code to all fields.
Field names should be easily understood by developers from the target
localflavor country. This means that English translations are usually
not the best name unless it's for something standard like postal code,
tax / VAT ID etc.
Prefer 'PostalCodeField' for postal codes as it's
international English; ZipCode is a term specific to the United
States postal system.
Add meaningful tests. 100% test coverage is not required but all
validation edge cases should be covered.
Add
.. versionadded:: <next-version>comment markers to newlocalflavors.
Add documentation for all fields.