Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A TypeError is raised when obtaining bic of a Ukrainian IBAN. #143

Closed
bernoreitsma opened this issue Jun 21, 2023 · 3 comments
Closed

A TypeError is raised when obtaining bic of a Ukrainian IBAN. #143

bernoreitsma opened this issue Jun 21, 2023 · 3 comments

Comments

@bernoreitsma
Copy link

bernoreitsma commented Jun 21, 2023

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?

@mdomke
Copy link
Owner

mdomke commented Jun 21, 2023

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.

@mdomke
Copy link
Owner

mdomke commented Jun 21, 2023

You know what: Let me quickly fix it. I guess this is easier since I have to create a release anyway...

@mdomke mdomke closed this as completed in 71a83f1 Jun 21, 2023
@bernoreitsma
Copy link
Author

Thanks for your work! 🙏

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

No branches or pull requests

2 participants