Skip to content
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

🔖 Release DB 0.77 -- part 3 #183

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/changelog/2024.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,54 @@

✨ Enable validation of `Literal` and other field types [PR](https://github.com/laminlabs/lamindb/pull/2177) [@sunnyosun](https://github.com/sunnyosun)

- A `Literal`-typed `CharField` is validated for any `Record`:

```python
from lnschema_core import Record, fields

CRISPRType = Literal[
"CRISPRi",
"CRISPRa",
]

class Treatment(Record):
system: CRISPRType = fields.CharField()

Treatment(system="crispr")
#> FieldValidationError:
#> system: crispr is not a valid value
#> → valid values are: CRISPRa, CRISPRi
```

- You can leverage [Django's rich field validation](https://docs.djangoproject.com/en/stable/ref/validators/) by inheriting from `ValidateFields` and using dedicated field types or custom regex expressions:

```python
from lnschema_core import Record, ValidateFields
from django.core.validators import RegexValidator

class Reference(Record, ValidateFields):
url: str | None = fields.URLField()
"""URL linking to the reference."""
doi: str = fields.CharField(
validators=[
RegexValidator(
regex=r"^(?:https?://(?:dx\.)?doi\.org/|doi:|DOI:)?10\.\d+/.*$",
message="Must be a DOI (10.1000/xyz123 or https://doi.org/10.1000/xyz123)",
)
],
)
"""A Digital Object Identifier (DOI)."""

Reference(doi="abc.ef", url="myurl.com")
#> FieldValidationError:
#> url: myurl.com is not valid
#> → Enter a valid URL.
#> doi: abc.ef is not valid
#> → Must be a DOI (10.1000/xyz123 or https://doi.org/10.1000/xyz123)
```

These possibilities are now leveraged in all schema modules.

- 🎨 Leverage a more concise way for defining registries: [lnschema-core](https://github.com/laminlabs/lnschema-core/pull/452) [findrefs](https://github.com/laminlabs/findrefs/pull/2) [ourprojects](https://github.com/laminlabs/ourprojects/pull/2) [clinicore](https://github.com/laminlabs/clinicore/pull/14) [cellregistry](https://github.com/laminlabs/cellregistry/pull/2) [@sunnyosun](https://github.com/sunnyosun)
- 🎨 Squash migrations for faster instance creation: [lnschema-core](https://github.com/laminlabs/lnschema-core/pull/453) [bionty](https://github.com/laminlabs/bionty/pull/162) [wetlab](https://github.com/laminlabs/wetlab/pull/75) [@sunnyosun](https://github.com/sunnyosun)

Expand Down
Loading