Skip to content

Commit 863cfd7

Browse files
authored
Merge pull request #856 from danielballan/update-metadata-fixup
Update metadata fixup
2 parents 71d3b46 + 51ba1ac commit 863cfd7

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

databroker/mongo_normalized.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import sys
1212
import threading
13+
from types import SimpleNamespace
1314

1415
from bson.objectid import ObjectId, InvalidId
1516
import cachetools
@@ -244,6 +245,7 @@ def __init__(
244245
self._clear_from_cache = clear_from_cache
245246
self._filler_creation_lock = threading.RLock()
246247
self.authz_shim = authz_shim
248+
self.node = SimpleNamespace(key=self.key)
247249

248250
@functools.cached_property
249251
def access_blob(self):
@@ -298,7 +300,7 @@ def metadata(self):
298300
return metadata
299301

300302
async def replace_metadata(self, metadata=None, specs=None, access_blob=None, drop_revision=False):
301-
if access_blob:
303+
if access_blob and (access_blob != self.access_blob):
302304
raise NotImplementedError("Updating access_blob on MongoDB-backed data is not supported.")
303305
if drop_revision:
304306
raise NotImplementedError("Must use drop_revision=False with databroker.mongo_normalized")
@@ -477,6 +479,7 @@ def __init__(
477479
self._event_collection = event_collection
478480
self._cutoff_seq_num = cutoff_seq_num
479481
self._run = run
482+
self.node = SimpleNamespace(key=self.key)
480483

481484
@property
482485
def access_blob(self):
@@ -522,7 +525,7 @@ def key(self):
522525
return self._metadata["descriptors"][0]["name"]
523526

524527
async def replace_metadata(self, metadata=None, specs=None, access_blob=None, drop_revision=False):
525-
if access_blob:
528+
if access_blob and (access_blob != self.access_blob):
526529
raise NotImplementedError("Updating access_blob on MongoDB-backed data is not supported.")
527530
if drop_revision:
528531
raise NotImplementedError("Must use drop_revision=False with databroker.mongo_normalized")

databroker/tests/test_broker.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,13 +1280,20 @@ def test_large_document():
12801280
list(run.documents())
12811281

12821282

1283-
@pytest.mark.xfail(reason="A problem for Future Dan and Phil")
12841283
def test_update(db, RE, hw):
12851284
RE.subscribe(db.insert)
12861285
if not hasattr(db, "v2"):
12871286
raise pytest.skip("v0 has no v2 accessor")
12881287
if getattr(db.v2, "is_sql", False):
12891288
raise pytest.skip("No 'chunks' to update on SQL-backed data")
1289+
1290+
class AuthZShim:
1291+
def bluesky_run_access_blob_from_metadata(self, metadata):
1292+
return {"tags": ["example"]}
1293+
1294+
authz_shim = AuthZShim()
1295+
db.v2.context.http_client.app.state.root_tree.authz_shim = authz_shim
1296+
12901297
c = db.v2
12911298
uid, = get_uids(RE(count([hw.det], 5)))
12921299
c[uid].update_metadata(
@@ -1304,12 +1311,10 @@ def test_update(db, RE, hw):
13041311

13051312
# Test stream update
13061313
md = c[uid]["primary"].metadata_copy()[0]
1307-
md["descriptors"][0]["data_keys"]["det"]["chunks"] = [
1308-
1 for _ in md["descriptors"][0]["data_keys"]["det"]["shape"]
1309-
]
1314+
md["descriptors"][0]["data_keys"]["det"]["chunks"] = [1]
13101315
c[uid]["primary"].update_metadata(metadata=md)
1311-
assert "chunks" in c[uid]["primary"]["data"]["det"]
1312-
assert all(x == 1 for x in c[uid]["primary"]["data"]["det"]["chunks"])
1316+
assert "chunks" in c[uid]["primary"].metadata["descriptors"][0]["data_keys"]["det"]
1317+
assert all(x == 1 for x in c[uid]["primary"].metadata["descriptors"][0]["data_keys"]["det"]["chunks"])
13131318

13141319
# Note: Vanilla Tiled does not enforce this.
13151320
# Perhaps it could be done at the authorization level.

0 commit comments

Comments
 (0)