Skip to content

Commit

Permalink
fix error appearing in dev environment:
Browse files Browse the repository at this point in the history
when the table of contense is created now an error appears.
This commit attepst to avoid this error.
  • Loading branch information
marionb committed Aug 21, 2023
1 parent 0b84bee commit ac0e8c9
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def __call__(self, value, system):
pdf_reader = PdfReader(pdf)
x = []
for i in range(len(pdf_reader.outline)):
x.append(pdf_reader.outline[i]['/Page']['/StructParents'])
if isinstance(pdf_reader.outline[i], list):
x.append(pdf_reader.outline[i][0]['/Page']['/StructParents'])
else:
x.append(pdf_reader.outline[i]['/Page']['/StructParents'])
try:
true_nb_of_toc = min(x)-1
except ValueError:
Expand Down

7 comments on commit ac0e8c9

@voisardf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marionb I checked, and when trying to get the pdf extract with 2.4.5 I get following error message:
File "/usr/local/lib/python3.9/site-packages/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py", line 118, in __call__ x.append(pdf_reader.outline[i]['/Page']['/StructParents']) TypeError: list indices must be integers or slices, not str

@voisardf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marionb @jwkaltz I did some more testing and as it seems, the issue above with 'list' is rather related to the mapfish print version:
Versions up to 29.4 work together with pyramid_oereb 2.4.5 without problems.
Version 3.30 and above lead to the error as the structure of pdf_reader.outline seems to have changed?

@marionb
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm OK that is interesting and good to know.
What do you suggest we should add the change or open a separate issue with a clan PR and test the commit above thoroughly?
Actually I got the exact same error message when developing so that was the reason why I added the change.

@voisardf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marionb
it would be interesting to ask your mfp developers why the pdf structure changes with 3.30 - is it voluntarily or by 'accident'?
the first element of pdf_reader.outline[i]['/Page']['/StructParents'] is as before, the following elements are in a list for whatever reason. So if it's not an accident, then the new case handling becomes mandatory, otherwise we may just notify the user group that some mfp versions are not compatible and take our time to add the exceptions.

@peterschaer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, this is the same problem as described in issue 137 over at pyramid_oereb_mfp.

@jwkaltz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is related to changes in MapFish-Print itself, but rather to changes in behavior by the pypdf library used within pyramid_oereb during generation of the print specification. @marionb and I are currently investigating in that direction.

@voisardf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterschaer thanks for pointing that out and the investigations already done - strangely enough it seems I didn't get the notifications back in june for whatever reason.
@jwkaltz thanks for checking the source of this regression

Please sign in to comment.