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

DocumentPart object has no attribute '_rels'. #541

Open
theodore86 opened this issue Apr 30, 2024 · 8 comments
Open

DocumentPart object has no attribute '_rels'. #541

theodore86 opened this issue Apr 30, 2024 · 8 comments
Labels

Comments

@theodore86
Copy link

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 theodore86 added the bug label Apr 30, 2024
@lcpprop
Copy link

lcpprop commented Apr 30, 2024

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'

@msp-corbett
Copy link

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

@joao-gabrielC
Copy link

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.

@elapouya
Copy link
Owner

elapouya commented May 1, 2024

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

@elapouya
Copy link
Owner

elapouya commented May 1, 2024

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

Please, could you test ?

@lcpprop
Copy link

lcpprop commented May 1, 2024

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

@msp-corbett
Copy link

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

@theodore86
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants