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

Modernize request parameter handling #641 #648

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

d-maurer
Copy link
Contributor

@d-maurer d-maurer commented Jun 12, 2019

Adresses #641.

From CHANGES.rst:

  • fully recursive aggregation which can handle structures of arbitrary depth

  • simplified processing model

  • support for special HTML5 features: _charset_ informs
    about the used form encoding; character references used
    to work around encoding limitations

  • treats parameter values internally as text
    (this means unicode for Python 2).
    For Python 2, the conversion to unicode is skipped if it
    results in a UnicodeDecodeError. The value is then used
    as is.

    For Python 2,
    the final values for parameters without converter and encoding directive
    are encoded with Zope's default encoding; character references
    are used for characters which cannot be encoded.

  • Errors encountered during request parameter processing are
    not reported immediately (at this stage, application specific
    error handling has not yet been set up). Instead, a
    post_traverse is registered which will raise
    a RequestParameterError exception after the traversal
    in the proper application context.
    The RequestParameterError describes all errors
    encountered during request parameter processing.

  • FileUpload has new attributes type (the associated
    MIME type or None) and the dict type_options
    (containing the provided MIME type parameters).

Backward incompatibilities:

  • a parameter must now follow a corresponding default parameter
    to override the default paramter; formerly the relative order
    of parameter and default parameter was of no importance.

    There is a new directive "conditional" which can also be used
    to define a default value. A conditional parameter is ignored,
    if there is already a corresponding parameter, and
    otherwise acts like a default parameter. Thus, its behaviour
    is comparable to the former bahaviour of "default".

  • aggregators are now applied from left to right; especially,
    their relative order is important.
    Formerly, aggregators were applied in a fixed order --
    independent of the order in which they were specified.

  • the converter functions (in ZPublisher.Converters)
    no longer support the conversion of files (because they
    do not know the encoding applicable for the file).
    The converter directives, however, can still be applied
    to (uploaded) files. They use the encoding explicitly
    specified via an encoding directive or fall back to
    Zope's default encoding.

Fixes #638, #634, #558.

Due to the backward incompatibilities, we might want to wait until Zope 5. In this case, and if Zope 5 drops Python 2 support, some Python 2 complexities could be removed.

Tests broken due to backward incompatible changes not yet fixed
@d-maurer d-maurer changed the title Modernize request parms#641 Modernize request parameter handling #641 Jun 12, 2019
@icemac
Copy link
Member

icemac commented Jun 13, 2019

@d-maurer Wow, this one is huge! Thank you for tackling these issues.
The current Zope roadmap says that Zope 4 will only a short term release. So there should be no 4.x feature releases. On the other hand Zope 5 should only drop Python 2 compatibility thus code successfully running on Zope 4 on Python 3 should also run without modifications on Zope 5. This means I'd like to postpone this PR until Zope 5 is released for the Zope 5.1 release.
Is this okay for you?

@d-maurer
Copy link
Contributor Author

d-maurer commented Jun 13, 2019 via email

@dataflake
Copy link
Member

Okay. But it would imply that a minor release (5.1) would introduce backward incompatibilities. Would it not be better to have those incomoatibilities in a major release?

I'd agree generally, but that pushes it out even further.

We already have internal agreement that we want to make the switch from 4.x to 5.0 as easy as possible so that there is no good reason to stick with 4.x. Release 5 will be purged of any Python 2 workarounds and thus will be a much easier platform to maintain going forward. But that means no new incompatibilities in release 5.0, so this PR cannot go into it.

Michael is suggesting 5.1 as a compromise so this won't have to wait all the time for a release 6, which has no clear time line at the moment.

@gforcada
Copy link
Member

just an idea: what about wrapping the code with an environment variable/configuration option/something of the sorts, so that it can be merged right away and be enabled as needed.

Together with some deprecation warnings might be enough signaling to encourage users to enable the new behavior.

@d-maurer
Copy link
Contributor Author

d-maurer commented Jun 14, 2019 via email

@icemac
Copy link
Member

icemac commented Jun 21, 2019

I think a feature toggle makes the code unnecessary complex as it requires to keep both variants. I find another dm.zopepatches.* package okay. We could add a ticket here for Zope 5.1 or even Zope 6 to reintegrate the package into Zope.

@d-maurer Would this be okay for you?

@d-maurer
Copy link
Contributor Author

d-maurer commented Jun 21, 2019 via email

@icemac icemac modified the milestones: 5.1, 5.2 Apr 20, 2021
@icemac icemac removed this from the 5.2 milestone Nov 19, 2021
@icemac icemac added this to the 5.4 milestone Nov 19, 2021
@dataflake dataflake modified the milestones: 5.4, 6.0 May 20, 2022
@dataflake
Copy link
Member

This is a great candidate for Zope 6

@d-maurer
Copy link
Contributor Author

I ask myself whether I should resume work on this PR.

Part of it has already arrived in the release: sanitize "taint" logic

2 parts remain:

  1. postpone request parameter error reports until after traversal (to report them via the "correct" error_log)
  2. more general but backward incompatible request parameter control

Currently, I think 1. could still be beneficial.
Regarding 2., developers with sophisticated need for request parameter control likely will use a form library (e.g. z3c.form or zope.formlib) rather than enhanced ZPublisher requst parameters. In view of this 2. is likely not worth the trouble caused by the backward incompatibility.
What do you think?

@dataflake
Copy link
Member

I agree.

@icemac icemac removed their request for review August 22, 2024 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

:lines converter converting to list of bytes instead of list of str
4 participants