Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion lamin_cli/_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,12 @@ def resolve_note_record(
parent_type = resolve_note_type_parent(ln, type_chain)
note_record = ln.Record.filter(name=note_name, type=parent_type).one_or_none()
if note_record is None and create_if_missing:
# Root notes and notes under a page stay in the type hierarchy.
# A record frame only accepts data records as rows.
note_record = ln.Record(
name=note_name,
type=parent_type,
is_type=True, # notes should appear in the type hierarchy
is_type=parent_type is None or not parent_type.is_frame,
).save()
return note_record

Expand Down
25 changes: 18 additions & 7 deletions tests/core/test_save_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path

import lamindb as ln
import pytest


def run_lamin(*args: str, cwd: Path | None = None) -> subprocess.CompletedProcess:
Expand All @@ -16,13 +17,20 @@ def run_lamin(*args: str, cwd: Path | None = None) -> subprocess.CompletedProces
)


def test_save_markdown_note_creates_record_and_recordblock():
topic = "cli-note-topic"
note_name = "cli-note"
branch = ln.Branch(name="cli_notes_branch").save()
type_record = ln.Record(name=topic, is_type=True).save()
@pytest.mark.parametrize("is_frame", [False, True])
def test_save_markdown_note_creates_record_and_recordblock(is_frame: bool):
suffix = "_frame" if is_frame else ""
topic = f"cli-note-topic{suffix}"
note_name = f"cli-note{suffix}"
branch = ln.Branch(name=f"cli_notes_branch{suffix}").save()
schema = (
ln.Schema(name=f"cli-note-schema{suffix}", itype=ln.Feature).save()
if is_frame
else None
)
type_record = ln.Record(name=topic, is_type=True, schema=schema).save()

notes_root = Path(__file__).parent / "notes"
notes_root = Path(__file__).parent / f"notes{suffix}"
note_dir = notes_root / topic
note_dir.mkdir(parents=True, exist_ok=True)
note_path = note_dir / f"{note_name}.md"
Expand All @@ -45,7 +53,7 @@ def test_save_markdown_note_creates_record_and_recordblock():
.first()
)
assert note_record is not None
assert note_record.is_type is True
assert note_record.is_type is not is_frame
assert note_record.branch == branch
readmes = note_record.ablocks.filter(kind="readme").order_by("created_at")
assert readmes.count() == 1
Expand Down Expand Up @@ -83,6 +91,8 @@ def test_save_markdown_note_creates_record_and_recordblock():
if ln.Record.filter(uid=type_record.uid).one_or_none() is not None:
type_record.refresh_from_db()
type_record.delete(permanent=True)
if schema is not None and ln.Schema.filter(uid=schema.uid).one_or_none():
schema.delete(permanent=True)
branch.delete(permanent=True)


Expand Down Expand Up @@ -288,6 +298,7 @@ def test_save_markdown_note_at_dev_dir_root_creates_record_and_recordblock():
)
note_record = ln.Record.filter(name=note_name, type=None, branch=branch).first()
assert note_record is not None
assert note_record.is_type is True
readmes = note_record.ablocks.filter(kind="readme").order_by("created_at")
assert readmes.count() == 1
assert "Root note" in readmes.first().content
Expand Down
Loading