-
Notifications
You must be signed in to change notification settings - Fork 1
feat(annotation): tag partial panels via status --tag-partial-panels #249
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
Merged
henrycgbaker
merged 3 commits into
main
from
feat/annotation-retrieval-completeness/04-tag-incomplete
Jul 7, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| """Shared safe metadata operations for live Argilla mutations. | ||
|
|
||
| Used by the ``--tag-partial-panels`` write path in ``panel_status``. | ||
| Centralises the two safety invariants that every metadata write must respect | ||
| on Argilla v2.8.0: | ||
|
|
||
| 1. **Argilla metadata is REPLACE, not merge.** Every ``dataset.records.log`` | ||
| call replaces the record's metadata wholesale. To avoid clobbering | ||
| existing keys, always fetch the current dict, merge in the update, and | ||
| send the FULL resulting dict. | ||
| 2. **Property declaration is additive and idempotent.** Adding a metadata | ||
| property to an existing dataset is non-destructive, but the SDK raises | ||
| if the property already exists (with override warning). Skip the add | ||
| when the property is already present. | ||
|
|
||
| Writes go via ``rg.Record(id=..., metadata={...})`` rather than a raw dict | ||
| payload: the SDK's ``IngestedRecordMapper`` flattens dict keys against the | ||
| dataset schema, so a ``{"id": ..., "metadata": {...}}`` shape would treat | ||
| "metadata" as an unknown top-level attribute and silently send an empty | ||
| metadata dict (wiping the record). Passing an ``rg.Record`` bypasses the | ||
| mapper. | ||
| """ | ||
|
|
||
| import logging | ||
| from collections.abc import Iterable, Mapping | ||
|
|
||
| import argilla as rg | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def ensure_metadata_property(dataset: rg.Dataset, prop: rg.MetadataType) -> bool: | ||
| """Idempotently declare ``prop`` on ``dataset``. | ||
|
|
||
| Returns True if the property was newly added (and the dataset settings | ||
| pushed to the server), False if it was already present. | ||
| """ | ||
| existing = dataset.settings.metadata[prop.name] | ||
| if existing is not None: | ||
| return False | ||
| dataset.settings.add(prop) | ||
| dataset.settings.update() | ||
| logger.info("Declared metadata property %r on dataset %s", prop.name, dataset.name) | ||
| return True | ||
|
|
||
|
|
||
| def build_metadata_upsert( | ||
| record: rg.Record, | ||
| updates: Mapping[str, object], | ||
| *, | ||
| remove_keys: Iterable[str] = (), | ||
| ) -> rg.Record | None: | ||
| """Merge ``updates`` into ``record.metadata`` and return an upsert Record. | ||
|
|
||
| Returns ``None`` when the merge produces no change (idempotent no-op). | ||
| Mutates ``record``'s metadata in place and returns it, so its fields (and | ||
| suggestions) ride along in the upsert payload: Argilla v2.8.0 rejects a | ||
| field-less record with 422 "fields cannot be empty" because the required | ||
| text fields must be present, so ``id`` + metadata alone is not a valid | ||
| upsert. | ||
|
|
||
| Callers batch the returned Records into a single ``dataset.records.log`` | ||
| call per dataset to amortise the round-trip. | ||
| """ | ||
| current = dict(record.metadata) | ||
| merged = dict(current) | ||
| merged.update(updates) | ||
| for key in remove_keys: | ||
| merged.pop(key, None) | ||
| if merged == current: | ||
| return None | ||
| for key, value in updates.items(): | ||
| record.metadata[key] = value | ||
| for key in remove_keys: | ||
| record.metadata.pop(key, None) | ||
| return record | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. This is all non-obvious behavior, but as best I can tell without testing, this is also recommended for v2.8.0. We're still just saying
"argilla>=2.0,<3.0"-- maybe it would be better to pin to 2.8 and force intentional version changes to reduce the risk of something changing about upsert behavior and clobbering information we want to retain?