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

Cannot set conditions with a '<' char when others are from type "file" #2231

Merged
merged 2 commits into from Jan 18, 2023

Conversation

xispa
Copy link
Member

@xispa xispa commented Jan 17, 2023

Description of the issue/feature this PR addresses

This Pull Request overcomes an issue with mixed type records in ZPublisher, that prevents to store conditions when a file type control (for a "file" type condition) is present before an input text type control (for a "text" type condition) and user enters a special character (that requires tainting) for the latter. See zopefoundation/Zope#1095 and screenshot below

Current behavior before PR

User cannot update analysis conditions if the value set contains the '<' character and the input text is rendered after a file control

Desired behavior after PR is merged

User can update analysis conditions regardless of the contents set for input values

Screenshot

Captura de 2023-01-16 11-38-58

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

When the value of a record received via POST should be tainted (e.g. when the
value contains the character '<'), ZPublisher (at least with 4.8.2) does it,
but it also does a deepcopy of the records processed earlier.

If one (or more) of these records processed earlier is from file type,
deepcopy cannot do the job and the following traceback arises:

```
Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 162, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 371, in publish_module
  Module ZPublisher.WSGIPublisher, line 232, in publish
  Module ZPublisher.HTTPRequest, line 737, in processInputs
  Module copy, line 163, in deepcopy\n  Module copy, line 230, in _deepcopy_list
  Module copy, line 190, in deepcopy\n  Module copy, line 334, in _reconstruct
  Module copy, line 163, in deepcopy\n  Module copy, line 257, in _deepcopy_dict
  Module copy, line 190, in deepcopy\n  Module copy, line 334, in _reconstruct
  Module copy, line 163, in deepcopy\n  Module copy, line 257, in _deepcopy_dict
  Module copy, line 182, in deepcopy\nTypeError: can't pickle cStringIO.StringO objects
```

As a result, the base error screen from plone "We’re sorry, but there seems to be an
error…" is rendered, but without any error or traceback information

Relevant debug info:

```
TypeError: can't pickle cStringIO.StringO objects
(Pdb++) where
[...]
-> self.execute()
[6]   /home/senaite/dev/buildout-cache/eggs/waitress-1.4.4-py2.7.egg/waitress/task.py(441)execute()
-> app_iter = self.channel.server.application(environ, start_response)
[7]   /home/senaite/dev/buildout-cache/eggs/Paste-3.5.0-py2.7.egg/paste/translogger.py(69)__call__()
-> return self.application(environ, replacement_start_response)
[8]   /home/senaite/dev/buildout-cache/eggs/Zope-4.8.2-py2.7.egg/ZPublisher/httpexceptions.py(30)__call__()
-> return self.application(environ, start_response)
[9]   /home/senaite/dev/buildout-cache/eggs/Zope-4.8.2-py2.7.egg/ZPublisher/WSGIPublisher.py(371)publish_module()
-> response = _publish(request, new_mod_info)
[10]   /home/senaite/dev/buildout-cache/eggs/Zope-4.8.2-py2.7.egg/ZPublisher/WSGIPublisher.py(232)publish()
-> request.processInputs()
[11] > /home/senaite/dev/buildout-cache/eggs/Zope-4.8.2-py2.7.egg/ZPublisher/HTTPRequest.py(738)processInputs()
-> reclist)
[12]   /home/senaite/dev/Python-2.7/lib/python2.7/copy.py(163)deepcopy()
-> y = copier(x, memo)
[13]   /home/senaite/dev/Python-2.7/lib/python2.7/copy.py(230)_deepcopy_list()
-> y.append(deepcopy(a, memo))
[14]   /home/senaite/dev/Python-2.7/lib/python2.7/copy.py(190)deepcopy()
-> y = _reconstruct(x, rv, 1, memo)
[15]   /home/senaite/dev/Python-2.7/lib/python2.7/copy.py(334)_reconstruct()
-> state = deepcopy(state, memo)
[16]   /home/senaite/dev/Python-2.7/lib/python2.7/copy.py(163)deepcopy()
-> y = copier(x, memo)
[17]   /home/senaite/dev/Python-2.7/lib/python2.7/copy.py(257)_deepcopy_dict()
-> y[deepcopy(key, memo)] = deepcopy(value, memo)
[18]   /home/senaite/dev/Python-2.7/lib/python2.7/copy.py(190)deepcopy()
-> y = _reconstruct(x, rv, 1, memo)
[19]   /home/senaite/dev/Python-2.7/lib/python2.7/copy.py(334)_reconstruct()
-> state = deepcopy(state, memo)
[20]   /home/senaite/dev/Python-2.7/lib/python2.7/copy.py(163)deepcopy()
-> y = copier(x, memo)
[21]   /home/senaite/dev/Python-2.7/lib/python2.7/copy.py(257)_deepcopy_dict()
-> y[deepcopy(key, memo)] = deepcopy(value, memo)
[22]   /home/senaite/dev/Python-2.7/lib/python2.7/copy.py(182)deepcopy()
-> rv = reductor(2)
(Pdb++) key
'conditions'
(Pdb++) item
'<'
(Pdb++) reclist[-1]
{'attachment': '', 'choices': '', 'description': '', 'required': '', 'title': 'Comentarios TGA', 'type': 'text', 'uid': '3939c785fcce47c9a3425d7e1d28aca2'}
(Pdb++) reclist[-2]
{'attachment': '', 'choices': '', 'description': 'Si el an\xc3\xa1lisis no se ajusta al esquema anterior, adjuntar fichero con las condiciones de ensayo', 'required': '', 'title': 'Fichero adjunto', 'type': 'file', 'uid': '3939c785fcce47c9a3425d7e1d28aca2', 'value': <ZPublisher.HTTPRequest.FileUpload object at 0x7fd973388b90>}
```
@ramonski
Copy link
Contributor

ramonski commented Jan 17, 2023

Hmm, maybe it would make sense to file a bug in https://github.com/zopefoundation/Zope/issues?
We did so for this one here as well (although still open): c209eb7

@xispa
Copy link
Member Author

xispa commented Jan 18, 2023

Hmm, maybe it would make sense to file a bug in https://github.com/zopefoundation/Zope/issues? We did so for this one here as well (although still open): c209eb7

Done zopefoundation/Zope#1095

@ramonski ramonski merged commit 7c4eb51 into 2.x Jan 18, 2023
@ramonski ramonski deleted the error-conditions-file-special-char branch January 18, 2023 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants