Skip to content

Commit 52f590b

Browse files
committed
🐛 Restore public QbField properties (#7480)
Restore the public `QbField` properties removed during the ORM model-system update: `annotation`, `doc`, `is_attribute`, and `is_subscriptable`. These properties are part of the public `aiida.orm` API and can be used by query helpers and plugin code. Add regression coverage for the restored accessors.
1 parent 7b63402 commit 52f590b

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

src/aiida/orm/fields.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from types import UnionType
1919

2020
from aiida.common.lang import isidentifier
21+
from aiida.common.warnings import warn_deprecation
2122

2223
__all__ = (
2324
'QbField',
@@ -92,11 +93,51 @@ def backend_key(self) -> str:
9293
return f'attributes.{self._backend_key}'
9394
return self._backend_key
9495

96+
@property
97+
def doc(self) -> str:
98+
"""Return the field documentation string."""
99+
warn_deprecation(
100+
'`QbField.doc` is deprecated. Inspect the corresponding ORM model field description instead.',
101+
version=3,
102+
stacklevel=2,
103+
)
104+
return self._doc
105+
95106
@property
96107
def dtype(self) -> t.Any | None:
97108
"""Return the primitive root type."""
98109
return extract_root_type(self._dtype)
99110

111+
@property
112+
def annotation(self) -> t.Any | None:
113+
"""Return the full type annotation."""
114+
warn_deprecation(
115+
'`QbField.annotation` is deprecated. Inspect the corresponding ORM model field annotation instead.',
116+
version=3,
117+
stacklevel=2,
118+
)
119+
return self._dtype
120+
121+
@property
122+
def is_attribute(self) -> bool:
123+
"""Return whether the field is stored in the attributes namespace."""
124+
warn_deprecation(
125+
'`QbField.is_attribute` is deprecated. Inspect the corresponding ORM model field metadata instead.',
126+
version=3,
127+
stacklevel=2,
128+
)
129+
return self._is_attribute
130+
131+
@property
132+
def is_subscriptable(self) -> bool:
133+
"""Return whether nested lookup through ``field['key']`` is supported."""
134+
warn_deprecation(
135+
'`QbField.is_subscriptable` is deprecated. Inspect the corresponding ORM model field metadata instead.',
136+
version=3,
137+
stacklevel=2,
138+
)
139+
return isinstance(self, QbDictField)
140+
100141
def in_(self, value: t.Iterable[t.Any]):
101142
"""Return a filter for only values in the list"""
102143
try:

tests/orm/test_fields.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from importlib_metadata import entry_points
1313

1414
from aiida import orm
15+
from aiida.common.warnings import AiidaDeprecationWarning
1516
from aiida.orm.fields import add_field
1617
from aiida.orm.pydantic import OrmMetadataField
1718
from aiida.plugins import load_entry_point
@@ -60,10 +61,20 @@ class AttributesModel(orm.Data.AttributesModel):
6061
node = NewNode()
6162

6263
assert 'key1' in node.fields
64+
with pytest.warns(AiidaDeprecationWarning, match='QbField.doc'):
65+
assert node.fields.key1.doc == ''
6366
assert node.fields.key1.dtype is str
67+
with pytest.warns(AiidaDeprecationWarning, match='QbField.annotation'):
68+
assert node.fields.key1.annotation is str
69+
with pytest.warns(AiidaDeprecationWarning, match='QbField.is_attribute'):
70+
assert node.fields.key1.is_attribute is True
71+
with pytest.warns(AiidaDeprecationWarning, match='QbField.is_subscriptable'):
72+
assert node.fields.key1.is_subscriptable is False
6473
assert isinstance(node.fields.key1, orm.fields.QbStrField)
6574
assert node.fields.key1.backend_key == 'attributes.key1'
6675
assert node.fields.key1 == node.fields.attributes.key1
76+
with pytest.warns(AiidaDeprecationWarning, match='QbField.is_subscriptable'):
77+
assert node.fields.attributes.is_subscriptable is True
6778

6879

6980
@pytest.mark.parametrize('key', ('|', 'some.field', '1key'))

0 commit comments

Comments
 (0)