python-docx-template icon indicating copy to clipboard operation
python-docx-template copied to clipboard

AttributeError: 'InlineImage' object has no attribute 'current_rendering_part'

Open rishi1804 opened this issue 3 years ago • 9 comments

Please explain something about this error. I am getting this when I try to render my JSON. There are multiple InlineImage objects in that JSON.

rishi1804 avatar Feb 03 '22 13:02 rishi1804

I am also getting a similar issue!

WilliamWCYoung avatar Mar 09 '22 15:03 WilliamWCYoung

please provide a fully runnig test case

elapouya avatar Mar 09 '22 15:03 elapouya

@WilliamWCYoung I solved the issue in my case. If you share the way you are using it, maybe I would be able to help.

rishi1804 avatar Mar 13 '22 09:03 rishi1804

I also solved my own case - it was after bumping. For the use case I have I have a custom class which assumes certain behaviour. Thanks for a great project!

WilliamWCYoung avatar Mar 15 '22 13:03 WilliamWCYoung

@rishi1804 @WilliamWCYoung Mind sharing how you fixed your issue? I'm running into the same error and am down the rabbit hole trying to debug what's going wrong. Could really use a nudge in the right direction.

joshuadavidthomas avatar Mar 24 '22 20:03 joshuadavidthomas

So the solution I had was very specific to the changes I made on-top of the package (I had assumed behaviour of private internal variables). If you have similar custom logic, I would suggest that you add debugging and check that the variables are there and populated as you expect, if not you'll maybe need to call extra methods. For instance, and I'm not by my code now, there was an init method that was now being called through the normal flow that I was not being called in my use case.

WilliamWCYoung avatar Apr 06 '22 20:04 WilliamWCYoung

Could you tell us what you changed in the code? I have the same problem but right now it is difficult for me to access the code of library

dalonsoma avatar Aug 18 '22 09:08 dalonsoma

please provide a fully runnig test case

elapouya avatar Aug 18 '22 09:08 elapouya

You must declare DocxTemplate prior to creating InLineImage e.g.,

first creating tpl instance here

tpl = DocxTemplate(f'C:\Python\template\{templateFileName}.docx')

later the JSON entry

{ 'image': InlineImage(tpl, imageFilePath, height=Inches(3.4), width=Inches(3.4*img.width/img.height)), 'label': f'PHOTO {phtoNameLetter}\n {item.properties["Photo_Caption"]}', })

civilengradil avatar Jul 13 '23 22:07 civilengradil