This URL does not pass validation: http://action-server/webhook. Any reason it should not?
Related to #246
I would also like such URLs to pass validation if possible just for purposes of local docker-compose development (even without kubernetes).
the short answer is, use DSN instead of url.
The long term answer is probably to merge DSN and URL and get it right.
Related to #541
For note, I got bitten by the same issue, for an URL pointing on a docker container in the same network (i.e. without TLD).
To reproduce :
from pydantic import UrlStr, dataclasses
@dataclasses.dataclass
class Test:
uri: UrlStr
Test('http://kong/test.png')
This will throw a Validation error :
ValidationError: 1 validation error for Test
uri
url string does not match regex (type=value_error.url.regex)
Trying with http://kong.fake-tld/test.png does not throw the validation error.
Using DSN instead of UrlStr is a workaround, but it removes the clarity and instinctiveness (no brainfuck) that can be achieved with pydantic on the rest : I found out about using DSN by digging into those GitHub issues, while the rest came naturally.
Could the URL validation regexp be modified to take into account this kind of URL ?
I've been thinking about this today, in v1 DSN and UrlStr should be unified and improved.
I guess the interface would be a bit like constr() and similar, something like:
AnyUrl virtually anything in a url structure, basically doesn't have spaces, has a scheme etc.strict_url(schema='postgres') url where the scheme has to be postgresHttpUrl an http(s) url, equivalent to strict_url(schema='https?') but cleaner and keeps mypy happyHttpsUrl an https url, equivalent to strict_url(schema='https') but cleaner and keeps mypy happyThe output would always be a string.
Woud this work?
Turns out this was possible all along, urlstr takes a require_tld argument that defaults to True, but can be set to False for cases like this.
However for v1 I've completely rewritten URL parsing to be easier to use and more powerful. Feedback very welcome on #755.
Most helpful comment
Turns out this was possible all along,
urlstrtakes arequire_tldargument that defaults toTrue, but can be set toFalsefor cases like this.However for v1 I've completely rewritten URL parsing to be easier to use and more powerful. Feedback very welcome on #755.