django / django-localflavor

Country-specific Django helpers, formerly of contrib fame
https://django-localflavor.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
828 stars 290 forks source link

IbanField doesn't validate anything #417

Closed AdrienHorgnies closed 4 years ago

AdrienHorgnies commented 4 years ago

Version: "Django==3.0.6", "django-localflavor==3.0.1"

I used localflavor.generic.models.IBANField for a Django models.Model attribute and it seems it accepts any value. I expect it to throw an exception or something when it receives an invalid value, but it's stores it in database like if the value is valid.

After some debugging, I see that calling the method clean_fields on such an instance throw indeed a ValidationError. But it doesn't happen when creating the instance... Did I do something wrong ? Or am I supposed to do something special for validation to occur ?

claudep commented 4 years ago

That's how Django validation generally works. Model cleaning is automatically called when you receive values through Django forms. If you programmatically build a model instance, it's your duty to call field validation.