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

EmailProperty seems to be required #369

Closed
ghost opened this issue Oct 1, 2018 · 6 comments
Closed

EmailProperty seems to be required #369

ghost opened this issue Oct 1, 2018 · 6 comments
Labels
documentation Issues requiring modifications to the documentation

Comments

@ghost
Copy link

ghost commented Oct 1, 2018

Despite email_distribution = EmailProperty(required=False,... the validation for Email Property seems to be required.

For example, when I try to submit a blank email field I get this back:
'' does not matches '[^@]+@[^@]+\\.[^@]+'

@ghost
Copy link
Author

ghost commented Oct 1, 2018

@ghost
Copy link
Author

ghost commented Oct 1, 2018

More thorough email regex
https://stackoverflow.com/a/201378/5739514

@StevenMapes
Copy link
Contributor

StevenMapes commented Oct 4, 2018

This is not a bug but is you misunderstanding what the required=False attribute means.

By setting the property as optional i.e. required=False you are saying that you do not need to set the property at all or you can set it to None. Setting it to an empty string is not the same as None as it has a value (an empy string) and thus it does not match the regex.

Here is an example of a simple class which I will try to save three instances of, one that will fail as it has an invalid email of an empty string and then the 2nd which will show the correct way of using the object without assigning the email and then the third which will show the alternative method where I'll set email=None

from neomodel import StructuredNode, StringProperty, EmailProperty

class SteveTest(StructuredNode):
    email=EmailProperty(required=False)
    name=StringProperty(required=True)

s = SteveTest(name="Should Fail", email="")
s.save()
# ValueError: '' does not matches '[^@]+@[^@]+\\.[^@]+'

# Don't set the property
s = SteveTest(name="Will work")
s.save()
# <SteveTest: {'email': None, 'name': 'Should Fail', 'id': 1}>

# Set the property to None
s1 = SteveTest(name="Or you can do this", email=None)
s1.save()
# <SteveTest: {'email': None, 'name': 'Should Fail', 'id': 2}>

@leonaidus
Copy link
Contributor

@StevenMapes can we change the error message to more readable form.
"Invalid Email" or something

@ghost
Copy link
Author

ghost commented Nov 21, 2018

I remember explicitly handling "" empty strings and setting them to None in response to this. As well as setting required to False.

I think this was more about the required = True tripping some flag that could not be flipped back properly. Sorry for being vague - forked a while back.

@aanastasiou aanastasiou added the documentation Issues requiring modifications to the documentation label Mar 5, 2019
@aanastasiou
Copy link
Collaborator

@HashRocketSyntax Thank you, this has now been highlighted in the documentation and will be rolled out in an upcoming release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues requiring modifications to the documentation
Projects
None yet
Development

No branches or pull requests

3 participants