fields.URL validation error should specify "not a valid FQDN" if trying to pass hostname without domain
The current validation error message: 'Not a valid URL.' is not descriptive enough to help the user, especially when they are passing a value that would appear to be a valid URL to most people, such as a docker hostname: http://test-url:8001
Sample code:
from marshmallow import Schema, fields
class TestSchema(Schema):
url = fields.URL(required=True)
TestSchema().load({"url": "http://192.168"}) // this works
TestSchema().load({"url": "http://test-url"}) // this doesn't work
TestSchema().load({"url": "derp"}) // and this has the same error message as http://test-url
This is because fields.URL has a default: require_tld=True, for require_tld: Whether to reject non-FQDN hostnames.
FQDN = fully-qualified domain name. i.e. http://server1.example.com is a FQDN, http://server1 is not.
Suggestion: error message should be more descriptive when require_tld is True, and validation fails FQDN requirement.
I have no objection to this. PR welcome.
Hi @lafrech Thanks - I took a swing at making a PR for it. Please take a look!
The main thing is just to improve "Not a valid URL" being a confusing message when inputting something that looks like a valid URL ...
If TLD is required, and "http://test-url" is passed, I set the error message to be: "URL must include a top-level domain (e.g., '.com', '.org')."
I wanted to include a note that it's because of the require_tld argument, which can be set to False, but obviously I don't think that's a helpful message for an end-user. Tricky balance to be helpful for developers, and not overly verbose for end-users.
So, it's just my initial attempt, and feedback is welcome!