From a5c7914dd6c5ef3d623277ba0e90bb1512e30cba Mon Sep 17 00:00:00 2001 From: Dimitri Yatsenko Date: Tue, 17 Feb 2026 15:01:57 -0600 Subject: [PATCH] fix: fetch(attrs, as_dict=True) no longer includes unrequested primary key In 0.14.x, fetch('col1', 'col2', as_dict=True) returned dicts containing only the requested attributes. In 2.x, proj() always includes primary key attributes, so the returned dicts contained extra keys the caller didn't ask for. Filter the dicts to only include requested attributes, restoring backward compatibility. Co-Authored-By: Claude Opus 4.6 --- src/datajoint/expression.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/datajoint/expression.py b/src/datajoint/expression.py index 883853cd3..b365e0891 100644 --- a/src/datajoint/expression.py +++ b/src/datajoint/expression.py @@ -716,7 +716,7 @@ def fetch( import warnings warnings.warn( - "fetch() is deprecated in DataJoint 2.0. " "Use to_dicts(), to_pandas(), to_arrays(), or keys() instead.", + "fetch() is deprecated in DataJoint 2.0. Use to_dicts(), to_pandas(), to_arrays(), or keys() instead.", DeprecationWarning, stacklevel=2, ) @@ -748,7 +748,10 @@ def is_key(attr): proj_attrs.extend(self.primary_key) else: proj_attrs.append(attr) - return self.proj(*proj_attrs).to_dicts(order_by=order_by, limit=limit, offset=offset, squeeze=squeeze) + dicts = self.proj(*proj_attrs).to_dicts(order_by=order_by, limit=limit, offset=offset, squeeze=squeeze) + # Filter to only requested attributes (proj always includes primary key) + requested = set(proj_attrs) + return [{k: v for k, v in d.items() if k in requested} for d in dicts] else: # fetch('col1', 'col2') or fetch('col1', 'col2', as_dict=False) -> tuple of arrays # This matches DJ 1.x behavior where fetch('col') returns array(['alpha', 'beta'])