Skip to content

Commit 515ef5a

Browse files
authored
Merge pull request #203 from khaeru/fix/empty-id
Preserve IdentifiableArtefact(id="")
2 parents dd877b3 + ac290a6 commit 515ef5a

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

doc/whatsnew.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
What's new?
44
***********
55

6-
.. Next release
7-
.. ============
6+
Next release
7+
============
8+
9+
- Bugfix: in v2.19.0 (only), :py:`IdentifableArtefact(id="")` resulted in the given ID (an empty :class:`str`) being incorrectly replaced with :data:`~.common.MissingID` (:pull:`203`).
810

911
v2.19.0 (2024-10-23)
1012
====================

sdmx/model/common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def __eq__(self, other):
146146
return isinstance(other, self.__class__)
147147

148148

149+
#: Singleton used for :attr:`.IdentifiableArtefact.id` if none given.
149150
MissingID = _MissingID()
150151

151152

@@ -245,7 +246,8 @@ def __post_init__(self):
245246
# Validate URN, if any
246247
self._urn = URN(self.urn)
247248

248-
if not self.id:
249+
if self.id is MissingID:
250+
# Try to retrieve an item ID from the URN, if any
249251
self.id = self._urn.item_id or self._urn.id or MissingID
250252
elif self.urn and self.id not in (self._urn.item_id or self._urn.id):
251253
# Ensure explicit ID is consistent with URN

sdmx/tests/model/test_common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ def test_eval_annotation(self, caplog) -> None:
9393

9494

9595
class TestIdentifiableArtefact:
96+
def test_init_empty_id(self):
97+
"""IdentifiableArtefact can be initialized with an empty :class:`str` as ID."""
98+
# No id= parameter → id attribute is MissingID
99+
ia0 = IdentifiableArtefact()
100+
assert common.MissingID == ia0.id
101+
assert common.MissingID is ia0.id
102+
103+
# Empty string parameter → id attribute is empty string
104+
ia1 = IdentifiableArtefact(id="")
105+
assert "" == ia1.id
106+
96107
def test_init_urn(self):
97108
"""IdentifiableArtefact can be initialized with URN."""
98109
ia = IdentifiableArtefact(urn=URN)

0 commit comments

Comments
 (0)