A `TypeError` is raised when obtaining `bic` of a Ukrainian IBAN.
bernoreitsma opened this issue · 3 comments
Steps to reproduce
from schwifty.iban import IBAN
iban = IBAN(iban="UA***ukrainian-IBAN-here***")
bic = iban.bic
results in the stacktrace
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "***/venv/lib/python3.8/site-packages/schwifty/iban.py", line 288, in bic
return BIC.from_bank_code(self.country_code, self.bank_code or self.branch_code)
File ***/venv/lib/python3.8/site-packages/schwifty/bic.py", line 114, in from_bank_code
return cls(spec[(country_code, bank_code)]["bic"])
File "***/venv/lib/python3.8/site-packages/schwifty/bic.py", line 52, in __init__
super().__init__(bic)
File "***/venv/lib/python3.8/site-packages/schwifty/common.py", line 13, in __init__
self._code = clean(code)
File "***/venv/lib/python3.8/site-packages/schwifty/common.py", line 50, in clean
return _clean_regex.sub("", s).upper()
TypeError: expected string or bytes-like object
Versions tested
Produced in python 3.8 but I suspect the bug is independent of the python-version.
Versions where the bug appears: 2023.3.0, 2023.2.1, 2023.2.0
.
Diagnosis
I think this is the offending commit: e4c4aef - the ukrainian banks have "bic": null
. With the BIC.from_bank_code
call we initialize a BIC
instance with None
, which is unexpected. Before it was added, we would catch a KeyError
in BIC.from_bank_code
which reraises as an InvalidBankCode
exception.
I don't know what would we preferred, either catch the null
-values or prevent them to be in the generated_ua.json
in the first place?
Hi @bernoreitsma!
Thank you for your detailed problem report. I think it would be best to avoid the null
-values in the generated JSON spec. Would you be willing to provide a pull-request for this? Nevertheless, there will be no BICs available for Ukrainian banks because the source we are using doesn't provide this information.
You know what: Let me quickly fix it. I guess this is easier since I have to create a release anyway...
Thanks for your work! 🙏