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

Urlfield before Stringfield produces an error #20

Closed
ChristianSauer opened this issue Aug 26, 2018 · 5 comments
Closed

Urlfield before Stringfield produces an error #20

ChristianSauer opened this issue Aug 26, 2018 · 5 comments

Comments

@ChristianSauer
Copy link

Just as a quick bug report:
This does not work:

@related.immutable
class ImageOptions(object):
    registry = related.URLField()
    email = related.StringField()

ValueError: No mandatory attributes allowed after an attribute with a default value or factory. Attribute in question: Attribute(name='email', default=NOTHING, validator=<instance_of validator for type (<class 'str'>,)>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({'key': None}), type=None, converter=<function str_if_not_none at 0x000001C58DFC6158>)

This does work:

@related.immutable
class ImageOptions(object):
    email = related.StringField()
    registry = related.URLField()

Rather surprising that the order of arguments matter

@imaurer
Copy link
Contributor

imaurer commented Aug 27, 2018

Looks like URLField has a default required value of false, as does UUIDField. All other fields are required equals true by default. Need to review whether I did that intentionally for some reason. If not, I will correct it. Thanks for the heads up.

@imaurer
Copy link
Contributor

imaurer commented Aug 27, 2018

Also, if you are curious about the root cause, it’s a “feature” of the underlying attrs library that supports positional arguments to classes.

python-attrs/attrs#38

@GeorgeLubaretsi
Copy link

@imaurer What are the consequences of making all fields to pass kw_only=True?

@GeorgeLubaretsi
Copy link

Looks like kw_only is only supported in Python 3+ python-attrs/attrs@123df67

@imaurer
Copy link
Contributor

imaurer commented Oct 13, 2018

The URL field no longer behaves in this arbitrarily restrictive manner:
https://github.com/genomoncology/related/blob/master/tests/issues/test_issue_020.py

Thanks @GeorgeLubaretsi for the PR. That's a bigger change that requires more deliberation.

@imaurer imaurer closed this as completed Oct 13, 2018
imaurer added a commit that referenced this issue Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants