From 1178cdbc15d4df5b381a5c1d2ef2a8b5c9032ac8 Mon Sep 17 00:00:00 2001 From: Nate Lust Date: Fri, 30 Jun 2023 17:54:16 -0400 Subject: [PATCH] Address review feedback --- doc/changes/DM-39582.api.md | 1 - doc/changes/DM-39582.removal.md | 1 + .../daf/butler/core/datastoreRecordData.py | 7 ------- .../lsst/daf/butler/core/persistenceContext.py | 6 ------ python/lsst/daf/butler/core/quantum.py | 4 +++- python/lsst/daf/butler/transfers/_yaml.py | 18 ++++++++++++++++-- 6 files changed, 20 insertions(+), 17 deletions(-) delete mode 100644 doc/changes/DM-39582.api.md create mode 100644 doc/changes/DM-39582.removal.md diff --git a/doc/changes/DM-39582.api.md b/doc/changes/DM-39582.api.md deleted file mode 100644 index ea9b5a751a..0000000000 --- a/doc/changes/DM-39582.api.md +++ /dev/null @@ -1 +0,0 @@ -Deprecate reconstituteDimensions argument from Quantum.from_simple diff --git a/doc/changes/DM-39582.removal.md b/doc/changes/DM-39582.removal.md new file mode 100644 index 0000000000..5b6bef359f --- /dev/null +++ b/doc/changes/DM-39582.removal.md @@ -0,0 +1 @@ +Deprecate reconstituteDimensions argument from `Quantum.from_simple`. diff --git a/python/lsst/daf/butler/core/datastoreRecordData.py b/python/lsst/daf/butler/core/datastoreRecordData.py index e3e33ba8c0..5a93078274 100644 --- a/python/lsst/daf/butler/core/datastoreRecordData.py +++ b/python/lsst/daf/butler/core/datastoreRecordData.py @@ -71,11 +71,6 @@ def direct( This method should only be called when the inputs are trusted. """ - key = frozenset(dataset_ids) - cache = PersistenceContextVars.serializedDatastoreRecordMapping.get() - if cache is not None and (value := cache.get(key)) is not None: - return value - data = SerializedDatastoreRecordData.__new__(cls) setter = object.__setattr__ # JSON makes strings out of UUIDs, need to convert them back @@ -89,8 +84,6 @@ def direct( if (id := record.get("dataset_id")) is not None: record["dataset_id"] = uuid.UUID(id) if isinstance(id, str) else id setter(data, "records", records) - if cache is not None: - cache[key] = data return data diff --git a/python/lsst/daf/butler/core/persistenceContext.py b/python/lsst/daf/butler/core/persistenceContext.py index 7d9f616e17..cf88389d7b 100644 --- a/python/lsst/daf/butler/core/persistenceContext.py +++ b/python/lsst/daf/butler/core/persistenceContext.py @@ -99,12 +99,6 @@ class PersistenceContextVars: r"""A cache of `SerializedDimensionRecord`\ s. """ - serializedDatastoreRecordMapping: ContextVar[ - dict[frozenset[str | uuid.UUID], SerializedDatastoreRecordData] | None - ] = ContextVar("serializedDatastoreRecordMapping", default=None) - r"""A cache of `SerializedDatastoreRecord`\ s. - """ - loadedTypes: ContextVar[dict[tuple[str, str], DatasetType] | None] = ContextVar( "loadedTypes", default=None ) diff --git a/python/lsst/daf/butler/core/quantum.py b/python/lsst/daf/butler/core/quantum.py index f3cf45e7f3..084e59d6e9 100644 --- a/python/lsst/daf/butler/core/quantum.py +++ b/python/lsst/daf/butler/core/quantum.py @@ -29,6 +29,7 @@ from typing import Any from lsst.utils import doImportType +from lsst.utils.introspection import find_outside_stacklevel from pydantic import BaseModel from .datasets import DatasetRef, DatasetType, SerializedDatasetRef, SerializedDatasetType @@ -416,7 +417,8 @@ def from_simple( if reconstitutedDimensions is not None: warnings.warn( "The reconstitutedDimensions argument is now ignored and may be removed after v 27", - category=DeprecationWarning, + category=FutureWarning, + stacklevel=find_outside_stacklevel("lsst.daf.butler"), ) # Unpersist all the init inputs diff --git a/python/lsst/daf/butler/transfers/_yaml.py b/python/lsst/daf/butler/transfers/_yaml.py index ae0cba4f8e..313c6c487a 100644 --- a/python/lsst/daf/butler/transfers/_yaml.py +++ b/python/lsst/daf/butler/transfers/_yaml.py @@ -25,7 +25,7 @@ import uuid import warnings -from collections import defaultdict +from collections import UserDict, defaultdict from collections.abc import Iterable, Mapping from datetime import datetime from typing import IO, TYPE_CHECKING, Any @@ -64,7 +64,21 @@ this version of the code. """ -_refIntId2UUID = defaultdict[int, uuid.UUID](uuid.uuid4) + +class _RefMapper(UserDict[int, uuid.UUID]): + """Create a local dict subclass which creates new deterministic UUID for + missing keys. + """ + + _namespace = uuid.UUID("4d4851f4-2890-4d41-8779-5f38a3f5062b") + + def __missing__(self, key: int): + newUUID = uuid.uuid3(namespace=self._namespace, name=str(key)) + self[key] = newUUID + return newUUID + + +_refIntId2UUID = _RefMapper() def _uuid_representer(dumper: yaml.Dumper, data: uuid.UUID) -> yaml.Node: