mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-28 05:24:00 +00:00
fix: validate remote tag checkout branch and version (#4853)
Remote tag checkout discarded the tag's branch and pinned its version on
the handle's own branch without checking that the version existed. This
could read a different snapshot or leave the handle pinned to a
nonexistent version.
Resolve the complete tag reference and reject cross-branch tags with an
error naming both branches. For a tag on the handle's branch, reuse
numeric checkout to validate the version before committing the selector
and freshness state. This also protects Python's
`open_table(version=tag)`, which delegates to tag checkout. To read a
tag on another branch, obtain that branch's handle first with
`checkout_branch` in Rust or `table.branches.checkout(...)` in Python.
The Python checkout docstrings and tag-based versioning guide document
this requirement.
Add 17 regression cases covering cross-branch tags in both directions,
main-branch aliases, same-branch reads, and failed validation on
writable and pinned handles. Twelve cases failed against the original
implementation. Update the existing freshness and schema-cache tests for
the validation request.
Validation:
- `cargo test --locked --profile ci --features remote -p lancedb --lib
remote:: -- --quiet` — 921 tests passed using mocked remote endpoints.
- `cargo fmt --all` — passed.
- `cargo clippy --locked --profile ci --features remote -p lancedb
--tests --examples` — passed.
- Python documentation: Ruff lint and formatting checks passed for the
Python tree, using Ruff 0.15.20 from `python/uv.lock`. Python syntax
checks passed; executable ASTs are unchanged. Repository-wide `ruff
check .` reports 59 pre-existing errors in six unchanged
`docs/web-tests` files; unrelated formatter changes were excluded.
Fixes #4843
<!-- lance-gatekeeper-fix:v1 agent=2253a7bdebba53465089b95bce66cb12
generation=1 -->
<!-- gatefixer-walkthrough:v1
head=35f8db881e36b83b9aab478cb5db72e485c9eca7 -->
## Change walkthrough
```mermaid
flowchart TD
resolve["Resolve tag reference"] --> branch{"Same branch?"}
branch -->|No| reject["Return branch error"]
branch -->|Yes| validate["Describe tag version"]
validate -->|Error| error["Return version error"]
validate -->|Success| pin["Pin validated snapshot"]
```
The selector and freshness state commit together under the version lock.
**Read:** [branch
guard](https://github.com/lancedb/lancedb/blob/35f8db881e36b83b9aab478cb5db72e485c9eca7/rust/lancedb/src/remote/table.rs#L4075-L4092)
→ [validation and
commit](https://github.com/lancedb/lancedb/blob/35f8db881e36b83b9aab478cb5db72e485c9eca7/rust/lancedb/src/remote/table.rs#L2865-L2893)
→ [tag and branch
guidance](https://github.com/lancedb/lancedb/blob/35f8db881e36b83b9aab478cb5db72e485c9eca7/docs/web/management/table.mdx#L1745-L1755).
<sub>Snapshot:
[35f8db8](https://github.com/lancedb/lancedb/commit/35f8db881e36b83b9aab478cb5db72e485c9eca7)</sub>
<!-- gatefixer-walkthrough:end -->
---------
Co-authored-by: Gatefixer <313497061+lancedb-gatefixer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -332,6 +332,16 @@ class RemoteTable(Table):
|
||||
)
|
||||
|
||||
def checkout(self, version: Union[int, str]):
|
||||
"""Check out a version number or tag as a read-only view in place.
|
||||
|
||||
A tag must belong to this handle's current branch. To read a tag on
|
||||
another branch, first obtain that branch's handle with
|
||||
`table.branches.checkout("branch_name")`, then call `checkout(tag)` on
|
||||
that handle. A tag on another branch raises an error without changing
|
||||
the current selection.
|
||||
|
||||
Call `checkout_latest()` to return to the latest version of this branch.
|
||||
"""
|
||||
result = LOOP.run(self._table.checkout(version))
|
||||
self._checkout_version = self.version
|
||||
return result
|
||||
|
||||
@@ -4247,6 +4247,12 @@ class Table(ABC):
|
||||
out state. To return the table to a normal state use
|
||||
`[Self::checkout_latest]`.
|
||||
|
||||
For Enterprise tables, a tag must belong to this handle's current branch.
|
||||
To read a tag on another branch, first obtain that branch's handle with
|
||||
`table.branches.checkout("branch_name")`, then call `checkout(tag)` on
|
||||
that handle. A tag on another branch raises an error without changing
|
||||
the current selection.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
version: int | str,
|
||||
@@ -10036,6 +10042,12 @@ class AsyncTable:
|
||||
out state. To return the table to a normal state use
|
||||
`[Self::checkout_latest]`.
|
||||
|
||||
For Enterprise tables, a tag must belong to this handle's current branch.
|
||||
To read a tag on another branch, first obtain that branch's handle with
|
||||
`await table.branches.checkout("branch_name")`, then call
|
||||
`await branch_table.checkout(tag)` on that handle. A tag on another
|
||||
branch raises an error without changing the current selection.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
version: int | str,
|
||||
|
||||
Reference in New Issue
Block a user