Skip to content

Commit

Permalink
Merge pull request #203 from khaeru/fix/empty-id
Browse files Browse the repository at this point in the history
Preserve IdentifiableArtefact(id="")
  • Loading branch information
khaeru authored Oct 23, 2024
2 parents dd877b3 + ac290a6 commit 515ef5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 4 additions & 2 deletions doc/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
What's new?
***********

.. Next release
.. ============
Next release
============

- 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`).

v2.19.0 (2024-10-23)
====================
Expand Down
4 changes: 3 additions & 1 deletion sdmx/model/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def __eq__(self, other):
return isinstance(other, self.__class__)


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


Expand Down Expand Up @@ -245,7 +246,8 @@ def __post_init__(self):
# Validate URN, if any
self._urn = URN(self.urn)

if not self.id:
if self.id is MissingID:
# Try to retrieve an item ID from the URN, if any
self.id = self._urn.item_id or self._urn.id or MissingID
elif self.urn and self.id not in (self._urn.item_id or self._urn.id):
# Ensure explicit ID is consistent with URN
Expand Down
11 changes: 11 additions & 0 deletions sdmx/tests/model/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ def test_eval_annotation(self, caplog) -> None:


class TestIdentifiableArtefact:
def test_init_empty_id(self):
"""IdentifiableArtefact can be initialized with an empty :class:`str` as ID."""
# No id= parameter → id attribute is MissingID
ia0 = IdentifiableArtefact()
assert common.MissingID == ia0.id
assert common.MissingID is ia0.id

# Empty string parameter → id attribute is empty string
ia1 = IdentifiableArtefact(id="")
assert "" == ia1.id

def test_init_urn(self):
"""IdentifiableArtefact can be initialized with URN."""
ia = IdentifiableArtefact(urn=URN)
Expand Down

0 comments on commit 515ef5a

Please sign in to comment.