-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow location fields to have localhost URLs #33
Conversation
Development/test environments use an object store that is generally served at `localhost:9000`. URLs that point to objects in this store obviously have the form `http://localhost:9000/{...}`. The pydantic field `HttpUrl` requires a TLD, which excludes `localhost`. Instead, we should use `AnyHttpUrl` which allows `localhost`.
Codecov Report
@@ Coverage Diff @@
## master #33 +/- ##
==========================================
- Coverage 94.74% 94.65% -0.10%
==========================================
Files 11 11
Lines 876 879 +3
==========================================
+ Hits 830 832 +2
- Misses 46 47 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@dchiquito - so this seems like a dev only hack rather than what should be in the schema, right? so perhaps we can use an environment variable and make HttpUrl map to AnyHttpUrl, as the official validation should not allow a non TLD ? |
My thought was that all of these fields are calculated by the API server, so it would be acceptable for these fields to accept any possible calculated value from any possible deployment. Providing a separate schema that is only used for dev/testing deployments sounds very difficult and much more complicated. |
all this would take is something like this: if os.environ["DEV_ENV"]:
HttpUrl = AnyHttpUrl this is only a pydantic dataclass issue as in the json schema there is no distinction of the URI types. |
Changing the result of importing a module based on environment variables sounds to me like it would cause a lot of headaches down the line, but if that is your preferred solution I can do that. |
@dchiquito - would you like a release to go alongside this? in which case please label this with release, patch. |
The default dandischema pydantic model does not allow localhost in URLs, which is a requirement for test and dev environments. To get around this, the dandischema module will subtly tweak the model to be more permissive with URLs if the environment variable DANDI_ALLOW_LOCALHOST_URLS is set. See dandi/dandi-schema#33
Development/test environments use an object store that is generally
served at
localhost:9000
. URLs that point to objects in this storeobviously have the form
http://localhost:9000/{...}
. The pydanticfield
HttpUrl
requires a TLD, which excludeslocalhost
. Instead, weshould use
AnyHttpUrl
which allowslocalhost
.