jhpyle / docassemble

A free, open-source expert system for guided interviews and document assembly, based on Python, YAML, and Markdown.
https://docassemble.org
MIT License
768 stars 252 forks source link

Error: AttributeError: 'str' object has no attribute 'signature' #766

Closed vestingz closed 4 months ago

vestingz commented 4 months ago

I am running docassemble via docker: sudo docker run -d -p 8088:80 -p 4430:443 --restart always --stop-timeout 600 jhpyle/docassemble

In the playground I have the following interview:

question: |
  What is your name?
fields:
  - Your name: user
---
question: |
  Please sign your name below.
mandatory: true
signature: user.signature
under: |
  ${ user }
---

After putting the signature in the respective field and pressing "Continue", the following error appears: Error: AttributeError: 'str' object has no attribute 'signature'

In a more complex interview where I had called the user.signature variable to fill a PDF, the following error appears:

Got error 'str' object has no attribute 'signature' Traceback (most recent call last):
  File "/usr/share/docassemble/local3.10/lib/python3.10/site-packages/docassemble/base/parse.py", line 8761, in assemble
    interview_status.populate(question.ask(user_dict, old_user_dict, 'None', [], None, None))
  File "/usr/share/docassemble/local3.10/lib/python3.10/site-packages/docassemble/base/parse.py", line 6707, in ask
    attachment_text = self.processed_attachments(user_dict)
  File "/usr/share/docassemble/local3.10/lib/python3.10/site-packages/docassemble/base/parse.py", line 6782, in processed_attachments
    items.append([x, self.prepare_attachment(x, the_user_dict), None])
  File "/usr/share/docassemble/local3.10/lib/python3.10/site-packages/docassemble/base/parse.py", line 7440, in prepare_attachment
    answer = val.text(the_user_dict).rstrip()
  File "/usr/share/docassemble/local3.10/lib/python3.10/site-packages/docassemble/base/parse.py", line 1614, in text
    return self.template.render(**the_user_dict)
  File "/usr/share/docassemble/local3.10/lib/python3.10/site-packages/docassemble/base/mako/template.py", line 445, in render
    return runtime._render(self, self.callable_, args, data)
  File "/usr/share/docassemble/local3.10/lib/python3.10/site-packages/docassemble/base/mako/runtime.py", line 874, in _render
    _render_context(
  File "/usr/share/docassemble/local3.10/lib/python3.10/site-packages/docassemble/base/mako/runtime.py", line 916, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/usr/share/docassemble/local3.10/lib/python3.10/site-packages/docassemble/base/mako/runtime.py", line 943, in _exec_template
    callable_(context, *args, **kwargs)
  File "memory:0x7fbdff089b40", line 23, in render_body
AttributeError: 'str' object has no attribute 'signature'

History was [{'question': <docassemble.base.parse.Question object at 0x7fbdffad9840>,
  'reason': 'mandatory question',
  'time': 1714076382.7307673},
 {'time': 1714076382.732539, 'variable': 'user'},
 {'question': <docassemble.base.parse.Question object at 0x7fbdff035c90>,
  'reason': 'considering',
  'time': 1714076382.73257},
 {'question': <docassemble.base.parse.Question object at 0x7fbdff035c90>,
  'reason': 'asking',
  'time': 1714076382.732587},
 {'done': True, 'time': 1714076382.7327154},
 {'question': <docassemble.base.parse.Question object at 0x7fbdffad9840>,
  'reason': 'mandatory question',
  'time': 1714076382.7331374}]

OS: Linux m720q 6.1.0-20-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.85-1 (2024-04-11) x86_64 GNU/Linux Docker version 26.1.0, build 9714adc Chromium 124.0.6367.60 (Guest profile with no addons)

jhpyle commented 4 months ago

Try changing the name of the variable name from user.signature to user_signature.

The dot . has special meaning in Python. If you use user.signature as a variable name, that assumes that user is a Python object. If you define user with a text field, then user will be a string of text (what Python calls an str) and a string cannot have attributes like .signature.

objects:
  - user: Individual
---
question: |
  What is your name?
fields:
  - Your name: user.name.first
---
question: |
  Please sign your name below.
mandatory: true
signature: user.signature
under: |
  ${ user }
jhpyle commented 4 months ago

Closing this for now.

vestingz commented 4 months ago

Thank you so much; that was indeed my mistake. I got confused reading the documentation.

Sorry for not replying earlier; I went on holidays and didn't check my mail for a while. Have a good day! :)