Skip to content

Commit 3d22a5f

Browse files
authored
fix: registration with a prefix (#1260)
* tst: Register with a prefix * fix: Apply default key_for_filename * fix: Delete _contents_ of registration target, not target itself * chore: update CHANGELOG
1 parent df86bf1 commit 3d22a5f

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Write the date in place of the "Unreleased" in the case a new version is release
1010
- Add ExternalPolicyDecisionPoint for authorization and an example with Open Policy Agent
1111

1212
### Changed
13+
1314
- Rename "create" scope to the more explicit "create:node"
1415
- Split "apikeys" scope into "create:apikeys" and "revoke:apikeys" scopes
1516

@@ -19,6 +20,7 @@ Write the date in place of the "Unreleased" in the case a new version is release
1920
- Allow clients to register standalone data directories as single nodes
2021
(e.g. Zarr stores) directly rather than discovering them by walking their
2122
parent directory.
23+
- Fix regression that broke registering files at a prefix.
2224

2325
## v0.2.2 (2025-11-25)
2426

tiled/_tests/test_directory_walker.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ async def test_same_filename_separate_directory(tmpdir):
9696
assert "a" in client["two"]
9797

9898

99+
@pytest.mark.asyncio
100+
async def test_register_prefix(tmpdir):
101+
"Register under a prefix"
102+
df1.to_csv(Path(tmpdir, "a.csv"))
103+
catalog = in_memory(writable_storage=str(tmpdir))
104+
with Context.from_app(build_app(catalog)) as context:
105+
client = from_context(context)
106+
x = client.create_container("x")
107+
y = x.create_container("y")
108+
y.create_container("z") # will be overwritten
109+
# Test that node is present.
110+
client["x", "y", "z"]
111+
await register(client, tmpdir, prefix="/x/y")
112+
# New node is present; old contents were overwritten.
113+
assert "a" in client["x/y"]
114+
assert "z" not in client["x/y"]
115+
116+
99117
@pytest.mark.asyncio
100118
async def test_mimetype_detection_hook(tmpdir):
101119
content = "a, b, c\n1, 2 ,3\n4, 5, 6\n"

tiled/client/register.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ async def register(
164164
for segment in prefix_parts:
165165
child_node = await anyio.to_thread.run_sync(node.get, segment)
166166
if child_node is None:
167-
key = key_from_filename(segment)
167+
key = settings.key_from_filename(segment)
168168
await create_node_or_drop_collision(
169169
node,
170170
structure_family=StructureFamily.container,
@@ -186,7 +186,9 @@ async def register(
186186
if overwrite:
187187
logger.info(f" Overwriting '/{'/'.join(prefix_parts)}'")
188188
# TODO When we have a tiled AsyncClient, use that.
189-
await anyio.to_thread.run_sync(partial(node.delete, recursive=True))
189+
await anyio.to_thread.run_sync(
190+
partial(node.delete_contents, recursive=True)
191+
)
190192
await _walk(node, Path(path), parsed_walkers, settings=settings)
191193
else:
192194
await register_single_item(node, path, is_directory=False, settings=settings)

0 commit comments

Comments
 (0)