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

missing_value doesn't work for Int fields #9

Closed
tseaver opened this issue Jan 18, 2015 · 2 comments · Fixed by #41
Closed

missing_value doesn't work for Int fields #9

tseaver opened this issue Jan 18, 2015 · 2 comments · Fixed by #41
Labels

Comments

@tseaver
Copy link
Member

tseaver commented Jan 18, 2015

In https://bugs.launchpad.net/zope.schema/+bug/98479, @webmaven reported:

The following creates an error:

page_ordinal = zope.schema.Int(
    title = _(u'Ordinal'),
    description=_(u'Order of the pages'),
    default=0,
    missing_value=0, #don't know why this doesn't work
    )

The error is as follows:

ConfigurationError: ('Invalid value for', 'class', "(None, (<type 'int'>, <type 'long'>))")

@mgedmin followed-up:

I've looked briefly at this error. The error is raised because the defaults for min_value and max_value are both None. This fails type checking, because None is not an int or a long. When missing_value is None, type checking is skipped.

I have to admit that I do not understand the semantics of missing_value.

I think that Int should allow min_value and max_value to be None regardless of the missing_value setting. Nones should be treated as minus infinity and plus infinity respectively.

@webmaven replied:

As I understand it, the value of missing_value is supposed to be used when the submitted form-field is empty. As opposed to default_value, which is supposed to pre-populate the form field.

@benji-york opined:

That's how it seems to me too. I looked briefly at the widget tests and couldn't figure out how to test it, so will have to look later (unless someone beats me to it, hint, hint).

@tseaver tseaver added the bug label Jan 18, 2015
@webmaven
Copy link
Contributor

@tseaver, does this old bug need a new test case or anything to be considered confirmed?

@tseaver
Copy link
Member Author

tseaver commented Jan 19, 2015

@webmaven the ideal would be a PR with a test case (based on your example) and a fix.

jamadden added a commit that referenced this issue Aug 13, 2018
Fixes #9

Note that you must still specify a `default` in that case. I'm not
sure that makes sense or not.

This impacts Int, Float, Decimal, DateTime, Timedelta, Date, and
Time---all the subclasses of Orderable. They all have a test case.

Also fix ValidatedProperty and DefaultProperty to do the right thing
when accessesd on the class and not the instance (which is to return
themself; previously they would raise AttributeError).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants