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

DocumentPart object has no attribute '_rels'.

Open theodore86 opened this issue 1 year ago • 8 comments

Describe the bug

A clear and concise description of what the bug is.

It seems like python-docx has released an new version:

python-docx==1.1.1
docxtpl==0.16.8
uri = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header'
    def get_headers_footers(self, uri):
>       for relKey, val in self.docx._part._rels.items():
E       AttributeError: 'DocumentPart' object has no attribute '_rels'. Did you mean: 'rels'?

theodore86 avatar Apr 30 '24 10:04 theodore86

I have the same issue. Everything was working the day before python-docx 1.1.1 release and not it gets this error. As soon as I specified that I want previous version of python-docx 1.1.0, everything started working again. Here is my traceback:


AttributeError Traceback (most recent call last) File , line 90 89 template_vars {"name":"John", "lastname":"Oliver"} ---> 90 doc.render(template_vars) 92 doc.save("<path_to_save>".docx")

File /local_disk0/.ephemeral_nfs/envs/.../lib/python3.10/site-packages/docxtpl/template.py:382, in DocxTemplate.render(self, context, jinja_env, autoescape) 379 # Headers 380 headers = self.build_headers_footers_xml(context, self.HEADER_URI, 381 jinja_env) --> 382 for relKey, xml in headers: 383 self.map_headers_footers_xml(relKey, xml) 385 # Footers

File /local_disk0/.ephemeral_nfs/envs/.../lib/python3.10/site-packages/docxtpl/template.py:338, in DocxTemplate.build_headers_footers_xml(self, context, uri, jinja_env) 337 def build_headers_footers_xml(self, context, uri, jinja_env=None): --> 338 for relKey, part in self.get_headers_footers(uri): 339 xml = self.get_part_xml(part) 340 encoding = self.get_headers_footers_encoding(xml)

File /local_disk0/.ephemeral_nfs/envs/.../lib/python3.10/site-packages/docxtpl/template.py:324, in DocxTemplate.get_headers_footers(self, uri) 323 def get_headers_footers(self, uri): --> 324 for relKey, val in self.docx._part._rels.items(): 325 if (val.reltype == uri) and (val.target_part.blob): 326 yield relKey, val.target_part

AttributeError: 'DocumentPart' object has no attribute '_rels'

lcpprop avatar Apr 30 '24 11:04 lcpprop

I've hit the same issue and rolled back to python-docx 1.1.0 as a fix.

msp-corbett avatar May 01 '24 03:05 msp-corbett

I've hit the same issue and rolled back to python-docx 1.1.0 as a fix.

Rolling back also fixed the issue for me.

joao-gabrielC avatar May 01 '24 13:05 joao-gabrielC

I am going to investigate about what's new in that python-docx version...

elapouya avatar May 01 '24 13:05 elapouya

I created the new docxtpl 0.17.0 : it requires python-docx 1.1.1+

Please, could you test ?

elapouya avatar May 01 '24 14:05 elapouya

Yes, everything works perfectly for me. Thank you so much! How about the others?

lcpprop avatar May 01 '24 15:05 lcpprop

Yes, working with docxtpl 0.17.0 and python-docx 1.1.2. Thanks!

msp-corbett avatar May 01 '24 23:05 msp-corbett

Thank, i have already locked the dependencies so it is not an major issue, it works.

theodore86 avatar May 02 '24 07:05 theodore86