marshmallow-code / marshmallow-code/marshmallow
fields.URL validation error should specify "not a valid FQDN" if trying to pass hostname without domain
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 738
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 7
Description
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:
```py
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with fields.URL validation and the require_tld option described in the issue. Distinguish a non-FQDN hostname such as http://test-url from malformed input such as derp, then verify the sample cases and ensure valid FQDNs continue to pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100