Skip to content

Commit a5c7914

Browse files
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 <noreply@anthropic.com>
1 parent 4a7e1e8 commit a5c7914

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/datajoint/expression.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ def fetch(
716716
import warnings
717717

718718
warnings.warn(
719-
"fetch() is deprecated in DataJoint 2.0. " "Use to_dicts(), to_pandas(), to_arrays(), or keys() instead.",
719+
"fetch() is deprecated in DataJoint 2.0. Use to_dicts(), to_pandas(), to_arrays(), or keys() instead.",
720720
DeprecationWarning,
721721
stacklevel=2,
722722
)
@@ -748,7 +748,10 @@ def is_key(attr):
748748
proj_attrs.extend(self.primary_key)
749749
else:
750750
proj_attrs.append(attr)
751-
return self.proj(*proj_attrs).to_dicts(order_by=order_by, limit=limit, offset=offset, squeeze=squeeze)
751+
dicts = self.proj(*proj_attrs).to_dicts(order_by=order_by, limit=limit, offset=offset, squeeze=squeeze)
752+
# Filter to only requested attributes (proj always includes primary key)
753+
requested = set(proj_attrs)
754+
return [{k: v for k, v in d.items() if k in requested} for d in dicts]
752755
else:
753756
# fetch('col1', 'col2') or fetch('col1', 'col2', as_dict=False) -> tuple of arrays
754757
# This matches DJ 1.x behavior where fetch('col') returns array(['alpha', 'beta'])

0 commit comments

Comments
 (0)