Do not raise KeyError when dumping after a Format line redefinition - #38
Do not raise KeyError when dumping after a Format line redefinition#38eeshsaxena wants to merge 1 commit into
Conversation
A section may contain more than one Format line, and the last one wins for the section field order. Lines parsed under an earlier order do not carry the new field names, so dumping them looked up a missing field and raised KeyError even though parse_string had accepted the document. Fall back to an empty value for a field a line does not carry, so a parsed document always dumps.
|
Ensuring a roundtrip works is good, though I am a little unsure about whether we should rather error on load here or alternatively not write such a bogus format line and silently skip it. Where/How did you encounter this file? Did you test how renderers or other ASS tools handle this case? My assumption would be that they ignore the second format line but you can never be sure in ASS world. |
|
Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix ( |
|
This fix is small code-wise but it can have non-trivial consequences that I have not had found the time to look into. I'd also appreciate if I could still communicate with a human here that actually reads my comments instead of bumping their "small fix" after only 2 days. |
|
You're right, bumping after two days was too impatient of me and I'm sorry. There's a real person on this end. If it helps, I'm glad to write out the edge cases I think a Format redefinition can hit so you have something concrete to check against, no rush at all. |
Document.dump_fileraisesKeyErroron a document thatparse_stringaccepted, when a section has a secondFormat:line:The last
Format:line wins for the section's field order, but the dialogue line was parsed under the earlier order and doesn't carry the new field names, soline.dumplooks up a field the line doesn't have. Since parsing already succeeded, dumping shouldn't blow up. I made a missing field dump as empty, so a parsed document always round-trips. Added a test; the suite passes.