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

List out of range error when opening file #25

Closed
dwasyl opened this issue Sep 10, 2024 · 7 comments
Closed

List out of range error when opening file #25

dwasyl opened this issue Sep 10, 2024 · 7 comments

Comments

@dwasyl
Copy link

dwasyl commented Sep 10, 2024

Hi there,

I have a particular docx file that I'm trying to use for a merge, but I keep getting a list index out of range error related to _get_field_type (specifically line 393 return s[0], s[1:] where instr is an empty string. Presumably an empty string shouldn't even be able to get to this point, so there's probably some error checking that's missed along the way.

I'm running into this when I run doc = MailMerge(file, remove_empty_tables=False, auto_update_fields_on_open="no") so that I can run doc.get_merge_fields().

I've tried going through the code base a bit to try and figure out the error, but clearly there is something about the way it's processing the source docx file that's causing this and just wondering if there were any initial ideas as to what might cause this problem. As it stands, I can't figure out it out enough to check for the issue in advance.

For reference, it's running Python 3.9.6, and docx-mailmerge2 version 0.6.3.

@dwasyl dwasyl changed the title List of our range error List out of range error when opening file Sep 10, 2024
@dwasyl
Copy link
Author

dwasyl commented Sep 10, 2024

After some additional testing, the error seems to occur when the merge fields are located in a table cell. When the fields are moved outside of the table, there is no problem at all.

Any idea why this would cause a problem?

@iulica
Copy link
Owner

iulica commented Sep 15, 2024

I'll have a look into it, can you provide a sample docx so that I can reproduce the error ?

@dwasyl
Copy link
Author

dwasyl commented Sep 16, 2024

@iulica Sure, here you go.
Doc merge table simple sample.docx

@iulica
Copy link
Owner

iulica commented Sep 19, 2024

Oh, I now noticed you are using the 0.6.3 version, that's quite old. Would you care testing it with the latest version ? Your document seems to work fine for me.

@iulica
Copy link
Owner

iulica commented Sep 19, 2024

Ok, I could reproduce it myself.

The problem was an empty field (I created it by pressing alt-f9) or something like this. It doesn't matter where it is, in a table or not. Your document didn't have it so it worked fine.

For the moment, you'll have to find this empty field and delete it from the document. You can see the fields by pressing ctrl-f9 or something like this, I have a mac and it works by pressing option-f9.

image

I will fix this in the next release, but for the moment it's not critical.

iulica added a commit that referenced this issue Sep 19, 2024
iulica added a commit that referenced this issue Sep 19, 2024
@iulica
Copy link
Owner

iulica commented Sep 19, 2024

I included a fix and released it with 0.8.2

@iulica iulica closed this as completed Sep 19, 2024
@dwasyl
Copy link
Author

dwasyl commented Sep 20, 2024

Great find! I hadn't even noticed that, but makes sense why it would cause that error.

Appreciate the fix so quickly!

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