csingley / ofxtools

Python OFX Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parsing Invalid OFX

aclindsa opened this issue · comments

Is there any plan to support parsing invalid OFX in limited cases?

For example, I'm getting an error like:

ofxtools.Types.OFXSpecError: Can't set INV401K.employername to XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: Value 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' exceeds max length=32

Obviously it would be better for the FI to abide by the standard, but I unfortunately don't have the luxury of fixing their code for them. In this case, it seems perfectly acceptable to either truncate the overly-long string field or simply allow it, potentially returning something indicating that the OFX was invalid. Perhaps the more flexible parsing would be non-default behavior and only enabled by an option on parser instantiation?

This is a job for ofxtools.Types.NagString

You can just change the class definition for ofxtools.models.invest.stmt.INV401K, setting employername = NagString(32, required=True). You can patch your own copy, monkey-patch it in your application, or just go ahead and submit it up to me. I don't mind relaxing these kinds of constraints that FIs frequently violate and that have no serious consequences; if you search through ofxtools.models you'll find several other models that have been changed in this manner.

Perfect, thanks for pointing me to that! I dug around a little in the code but didn't manage to find it.