Closed ashleysommer closed 2 weeks ago
Probably should remove the Optional
typing and remove the default None
value in the pydantic settings[1].
https://github.com/RDFLib/prez/blob/c5d39319418cb7442c97562fc0babe2e4c773c61/prez/config.py#L33
At least that way, it'll fail on startup when the config object is populated and no value is found for the env var.
[1] https://docs.pydantic.dev/latest/concepts/pydantic_settings/
@edmondchuc Sounds like a sensible and pydantic way to do it to me.
It's optional as the sparql_repo_type can be "pyoxigraph" in which case no sparql endpoint is required. We can do a slightly more complex validation on startup though to check if sparql_repo_type = "remote" then a sparql_endpoint must be specified
Ah, that's why it's optional! I forgot about the different backend types.
If you forget to provide a value for the SPARQL_ENDPOINT variable (either through env var or in the config file), Prez will start and during startup it will emit an error like this:
Notice it gets all the way into the depths of the
httpx
library before anyone notices the url isNone
.It would be easy to add a check on startup (before calling
healthcheck_sparql_endpoints()
) to ensureSPARQL_ENDPOINT
is not None, and emit a better error to the user for how to fix it.