marshmallow-code / marshmallow-code/marshmallow

fields.URL validation error should specify "not a valid FQDN" if trying to pass hostname without domain

Open
#2,243 2 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.