dandi / dandi/dandi-schema

linkml model: how to add "run-time" or "instance specific" validations

Open
#274 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
7
Forks
15
PR merge metrics
No merged PRs in 30d

Description

ATM in models.py we have

```python
try:
DANDI_INSTANCE_URL = os.environ["DJANGO_DANDI_WEB_APP_URL"]
...
else:
# Ensure no trailing / for consistency
DANDI_INSTANCE_URL_PATTERN = re.escape(DANDI_INSTANCE_URL.rstrip("/"))
...
PUBLISHED_VERSION_URL_PATTERN = (
rf"^{DANDI_INSTANCE_URL_PATTERN}/dandiset/{VERSION_PATTERN}$"
)
```
which are later used in validation of some properties

```python
class PublishedDandiset(Dandiset, Publishable):
...
@field_validator("url")
@classmethod
def check_url(cls, url: AnyHttpUrl) -> AnyHttpUrl:
if not re.match(PUBLISHED_VERSION_URL_PATTERN, str(url)):
raise ValueError(
f'string does not match regex "{PUBLISHED_VERSION_URL_PATTERN}"'
)
return url
```

and so on.

Typically it is to restrict some generic check (for a URL) to become more specific for a specific instance. Hence this relates to

- #76

It is not totally unlike what we do for OpenNeuro where generic BIDS doesn't disallow not having `sub-*` subfolders but then for OpenNeuro instance it is desired to be required. (TODO: add link to issues where I reported on that etc)

This also seems to relate to

- https://github.com/dandi/dandi-schema/issues/205

as to allow for "composition" of validations/models (draft vs publishable, published etc).

@candleindark recalled https://linkml.io/linkml/developers/schemaview.html which might be used here.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.