question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support empty string with EmailStr validation

See original GitHub issue

Hello,

I configured the following field:

representative_email: EmailStr = None

When passing an empty string “” as value, I get the following error:

Email address is not valid (error_type=ValueError track=EmailStr)

How can I configure va validator to support those values a I can’t change the incoming format?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
jaddisoncommented, Oct 24, 2019

For anyone curious on a working solution here:

class EmailEmptyAllowedStr(EmailStr):
    @classmethod
    def validate(cls, value: str) -> str:
        if value == "":
            return value
        return super().validate(value)
2reactions
samuelcolvincommented, May 22, 2018

Maybe you need Optional[EmailStr]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support empty string with EmailStr validation #181 - GitHub
Hello, I configured the following field: representative_email: EmailStr = None When passing an empty string "" as value, I get the following ...
Read more >
Allow empty string for EmailAddressAttribute - Stack Overflow
You have two options: Convert string.Empty to null on the Email field. Many times that is perfectly acceptable.
Read more >
Field Types - pydantic
pydantic supports many common types from the python standard library. ... EmailStr: requires email-validator to be installed; the input string must be a ......
Read more >
email-validator - PyPI
A robust email address syntax and deliverability validation library for Python by Joshua Tauberer. This library validates that a string is of the...
Read more >
Javascript for validating email used in a mapping Function.
Has anyone tried using Javascript within a function to validate if an email address is valid? ... public static boolean validateEmail(String emailStr) {....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found