-
Notifications
You must be signed in to change notification settings - Fork 22
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
IField.required attribute is True but must not. #104
Comments
Is the problem that the widget doesn't provide a way to not set a value for the field? IIRC, 'required' for a field is all about whether then attribute must be provided by the object described by the schema. |
No, the widget is just the symptom showing up whats set at the field. The plone schema editor uses definition as-is. There is no (and also must be no) need to change this, because the editor has to strictly follow the definition. And the symptom, as said, is that it not work as expected. |
Jens W. Klein wrote at 2021-1-29 08:53 -0800:
No, the widget is just the symptom showing up whats set the field. The plone schema editor uses definition as-is. There is no (and also must be no) need to change this, because the editor has to strictly follow the definition. And the symptom, as said, is that it work as expected.
The actual problem is that a `Bool` field it typically
represented as a checkbox at the browser interface.
A checkbox has only 2 states.
Therefore, "unset" is interpreted as "no value provided"
and as a consequence incompatible with "required".
`zope.schema` has other use cases than browser interfaces.
And at the Python level, "unset" and "no value provided"
are distinguishable. There, `required` makes sense.
Therefore, I strongly suggest to mark this change as a
backward incompatible change.
|
This has strange side effects when running the Plone 6 Jenkins tests. Jenkins gets confused and can't even show us how many tests failed in the overview. But let's pick one, that I can see locally too:
This is with
In the tests this is used by When I add If that is the only problem, then this change in zope.schema seems fine, but there are more failures, for example:
I don't see how to trigger this failure locally yet. Maybe the earlier |
As the fix seems to lead to other problems I am going to re-open this issue. |
This was the default for Bool fields until and including zope.schema 6.0.1. In 6.1.0 this changed. Since we have a default in the field definition, it does not look like any changes are needed for people using `plone.rest`. Without this, we get errors like this on Jenkins with Plone coredev 6: ``` $ bin/test -s plone.rest ... File "/Users/maurits/shared-eggs/cp38/zope.configuration-4.4.0-py3.8.egg /zope/configuration/config.py", line 869, in finish actions = self.handler(context, **args) zope.configuration.xmlconfig.ZopeXMLConfigurationError: File "/Users/maurits/community/plone-coredev/6.0/src/plone.rest/src/plone/rest/testing.zcml", line 163.2-167.6 TypeError: cors_policy_directive() missing 1 required positional argument: 'allow_credentials' ``` See zopefoundation/zope.schema#104 (comment)
Branch: refs/heads/master Date: 2021-02-10T15:49:52+01:00 Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org> Commit: plone/plone.rest@8d1ed68 Explicitly make allow_credentials required in CORS policy. This was the default for Bool fields until and including zope.schema 6.0.1. In 6.1.0 this changed. Since we have a default in the field definition, it does not look like any changes are needed for people using `plone.rest`. Without this, we get errors like this on Jenkins with Plone coredev 6: ``` $ bin/test -s plone.rest ... File "/Users/maurits/shared-eggs/cp38/zope.configuration-4.4.0-py3.8.egg /zope/configuration/config.py", line 869, in finish actions = self.handler(context, **args) zope.configuration.xmlconfig.ZopeXMLConfigurationError: File "/Users/maurits/community/plone-coredev/6.0/src/plone.rest/src/plone/rest/testing.zcml", line 163.2-167.6 TypeError: cors_policy_directive() missing 1 required positional argument: 'allow_credentials' ``` See zopefoundation/zope.schema#104 (comment) Files changed: A news/104.bugfix M src/plone/rest/zcml.py Repository: plone.rest Branch: refs/heads/master Date: 2021-02-10T17:48:27+01:00 Author: Maurits van Rees (mauritsvanrees) <m.van.rees@zestsoftware.nl> Commit: plone/plone.rest@cc8e7b3 Merge pull request #115 from plone/maurits/allow-credentials-required Explicitly make allow_credentials required in CORS policy. Files changed: A news/104.bugfix M src/plone/rest/zcml.py
The meta level of definitions is hard, here and at plone.rest. I would consider it edge cases. |
Looks like the other failures were somehow fallout from the single problem in |
Jenkins stays green after merge. I close this. |
Looks like this change broke my legacy app's test suite! zope.app.form's getWidgetsData() now omits Bool() fields from the returned data dictionary and I get KeyErrors in my code instead of False values. Downgrading to zope.schema 6.0.1 fixes those tests. I'm still trying to figure out what is happening. I think I'll cope, and there's no need to revert the change (but I reserve the right to change my mind ;). |
I'm not sure this was a good idea. On the business level I could have
We can render the widget as a radio:
With 6.0.1 the user had to choose yes or no because Bool was required. With 6.1 the user can submit the form without picking one. It's my problem that I rely on field defaults, but honestly, who sets required True on a Bool? Also of course z3c.form tests are failing like crazy because of this. |
It is strange though: the PR for this issue seems to have more effects than simply changing if a field is required or not, even though that is exactly the only change that was done. In easyform, the checkbox for the standard mailer object is not checked anymore, and when I manually check it and save the form, the change is not persisted. |
Should this change get rolled back as it breaks more than it helps? |
I just saw that in zopefoundation/z3c.form#104 the problems in z3c.form were already fixed. |
In my opinion it's a damn fundamental change, which can do much harm without being noticed. I fixed the z3c.form tests because we needed the MultiConverter fix. The solution for our code was to add |
I think for the vast majority of Bool fields, But there are side effects, like the easyform issue I link to where there is a checkbox that you can select, but the value is not saved. I have not dived into why that is. There can also be Bool fields like "I agree to the terms" that are intended to be required: you must check the box before you can successfully submit the form. When the field definition unknowingly relies on the old default (required=True), the form will now be broken. Previously, all fields were required, unless you explicitly specified differently. It seems best not to change this suddenly. @jensens What problem did this solve for you that could not have been solved by adding a Quoting from your original comment:
My expectations are different. What actually happened originally is exactly what I expect. |
Important here: The initial problem description is on the meta-model-level (and at least partly at meta-meta-level) of models (aka schemas in Zope). It was not a problem on the actual schema. Attention, this is confusing! Note: it is because we define the meta-model (fields) the way as we define the model (schema) itself, using its own definitions. To break out, Python is our meta-meta level of the model Change 1: Change 2: ping @agitator |
That helps. Say you define a schema with two fields: question is a TextLine, answer is a Bool. The problems start on the meta level. I can't completely wrap my head around this, but I can imagine that this causes problems, along the lines of: you are required to have a I think it indeed makes sense to keep the first change, and revert the second change. Can you make a PR? |
You're basically right, and yes, if it come to the meta (and meta meta) model levels things get a bit brain-twisting. I'll create a PR. |
merged |
BUG/PROBLEM REPORT (OR OTHER COMMON ISSUE)
What I did:
We use
IField
https://github.com/zopefoundation/zope.schema/blob/master/src/zope/schema/interfaces.py#L192 with z3c.form to generate a form (plone.schemaeditor).What I expect to happen:
The
required
of above schema interface attribute should render a field I can save checked or unchecked https://github.com/zopefoundation/zope.schema/blob/master/src/zope/schema/interfaces.py#L192What actually happened:
The field can only be saved as selected, because it is required.
What version of Python and Zope/Addons I am using:
Plone with recent zc3.form
Analysis:
IField.required
is a Bool field withrequired=True
. This z3c.form does what it is told and render the field required.A Bool fields default for required is
True
. It is inherited fromField
https://github.com/zopefoundation/zope.schema/blob/master/src/zope/schema/_bootstrapfields.py#L222Solution
Explicitly set
IField.required
Bool
field definition toFalse
like so:The text was updated successfully, but these errors were encountered: