Skip to content

Commit 4b2b158

Browse files
committed
Enhance UUID handling during import: clarify regeneration conditions and update related messages
1 parent 4154595 commit 4b2b158

File tree

6 files changed

+54
-25
lines changed

6 files changed

+54
-25
lines changed

datalab/gui/main.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,23 +1658,32 @@ def open_h5_files(
16581658
else:
16591659
reset_all = Conf.io.h5_clear_workspace.get()
16601660
if Conf.io.h5_clear_workspace_ask.get():
1661+
# Build message with optional note for native workspace import
1662+
msg = _(
1663+
"Do you want to clear current workspace "
1664+
"(signals and images) before importing data from "
1665+
"HDF5 files?"
1666+
)
1667+
# Only show the UUID conflict note when importing native DataLab
1668+
# workspace files (import_all=True), not when using HDF5 browser
1669+
if import_all:
1670+
msg += "<br><br>" + _(
1671+
"<u>Note:</u> If you choose <i>No</i>, when importing "
1672+
"DataLab workspace files, objects with conflicting "
1673+
"identifiers will have their processing history lost "
1674+
"(features like 'Show source' and 'Recompute' will not "
1675+
"work for those objects). Non-conflicting objects will "
1676+
"preserve their processing history."
1677+
)
1678+
msg += "<br><br>" + _(
1679+
"Choosing to ignore this message will prevent it "
1680+
"from being displayed again, and will use the "
1681+
"current setting (%s)."
1682+
) % (_("Yes") if reset_all else _("No"))
16611683
answer = QW.QMessageBox.question(
16621684
self,
16631685
_("Warning"),
1664-
_(
1665-
"Do you want to clear current workspace "
1666-
"(signals and images) before importing data from "
1667-
"HDF5 files?<br><br>"
1668-
"<b>Note:</b> If you choose <b>No</b>, the imported "
1669-
"objects' processing history will be lost "
1670-
"(features like 'Show source' and 'Recompute' will not "
1671-
"work) because object identifiers will be regenerated "
1672-
"to avoid conflicts.<br><br>"
1673-
"Choosing to ignore this message will prevent it "
1674-
"from being displayed again, and will use the "
1675-
"current setting (%s)."
1676-
)
1677-
% (_("Yes") if reset_all else _("No")),
1686+
msg,
16781687
QW.QMessageBox.Yes | QW.QMessageBox.No | QW.QMessageBox.Ignore,
16791688
)
16801689
if answer == QW.QMessageBox.Yes:

datalab/gui/panel/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,10 @@ def deserialize_object_from_hdf5(
927927
# When reopening a workspace (reset_all=True), preserve original UUIDs
928928
# so that processing parameter references (source_uuid, source_uuids)
929929
# remain valid and features like "Show source" and "Recompute" work.
930+
# When importing, only regenerate UUID if it conflicts with an existing one.
930931
if not reset_all and isinstance(obj, (SignalObj, ImageObj, ObjectGroup)):
931-
set_uuid(obj)
932+
if self.objmodel.has_uuid(get_uuid(obj)):
933+
set_uuid(obj)
932934
return obj
933935

934936
@abc.abstractmethod

datalab/gui/settings.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ class IOSettings(gds.DataSet):
112112
help=_(
113113
"If enabled, the current workspace will be cleared before loading a "
114114
"new HDF5 file.\n"
115-
"If disabled, imported objects' processing history will "
116-
"be lost (features like 'Show source' and 'Recompute' will not work) "
117-
"because object identifiers will be regenerated to avoid conflicts."
115+
"If disabled, when importing DataLab workspace files, only objects with "
116+
"conflicting identifiers will have their processing history lost "
117+
"(features like 'Show source' and 'Recompute' will not work for those "
118+
"objects). Non-conflicting objects will preserve their processing history."
118119
),
119120
)
120121
h5_clear_workspace_ask = gds.BoolItem("", _("Ask before clearing workspace"))

datalab/locale/fr/LC_MESSAGES/datalab.po

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ msgid ""
66
msgstr ""
77
"Project-Id-Version: datalab\n"
88
"Report-Msgid-Bugs-To: [email protected]\n"
9-
"POT-Creation-Date: 2025-11-15 17:20+0100\n"
9+
"POT-Creation-Date: 2025-11-15 17:56+0100\n"
1010
"PO-Revision-Date: 2025-05-22 15:46+0200\n"
1111
"Last-Translator: Christophe Debonnel <[email protected]>\n"
1212
"Language: fr\n"
@@ -936,9 +936,15 @@ msgstr "Êtes-vous sûr de vouloir désactiver le rafraîchissement automatique
936936
msgid "Save"
937937
msgstr "Enregistrer"
938938

939+
msgid "Do you want to clear current workspace (signals and images) before importing data from HDF5 files?"
940+
msgstr "Souhaitez-vous vider l'espace de travail actuel (signaux et images) avant d'importer des données depuis des fichiers HDF5 ?"
941+
942+
msgid "<u>Note:</u> If you choose <i>No</i>, when importing DataLab workspace files, objects with conflicting identifiers will have their processing history lost (features like 'Show source' and 'Recompute' will not work for those objects). Non-conflicting objects will preserve their processing history."
943+
msgstr "<u>Note :</u> Si vous choisissez <i>Non</i>, lors de l'importation de fichiers d'espace de travail DataLab, les objets ayant des identifiants en conflit perdront leur historique de traitement (les fonctionnalités telles que 'Afficher la source' et 'Retraiter' ne fonctionneront pas pour ces objets). Les objets sans conflit conserveront leur historique de traitement."
944+
939945
#, python-format
940-
msgid "Do you want to clear current workspace (signals and images) before importing data from HDF5 files?<br><br><b>Note:</b> If you choose <b>No</b>, the imported objects' processing history will be lost (features like 'Show source' and 'Recompute' will not work) because object identifiers will be regenerated to avoid conflicts.<br><br>Choosing to ignore this message will prevent it from being displayed again, and will use the current setting (%s)."
941-
msgstr "Souhaitez-vous effacer l'espace de travail actuel (signaux et images) avant d'importer des données depuis des fichiers HDF5 ?<br><br><b>Remarque :</b> Si vous choisissez <b>Non</b>, l'historique de traitement des objets importés sera perdu (des fonctionnalités telles que 'Afficher la source' et 'Recalculer' ne fonctionneront pas) car les identifiants d'objet seront régénérés pour éviter les conflits.<br><br>Choisir d'ignorer ce message empêchera son affichage ultérieur et utilisera le réglage actuel (%s)."
946+
msgid "Choosing to ignore this message will prevent it from being displayed again, and will use the current setting (%s)."
947+
msgstr "Ignorer ce message empêchera son affichage ultérieur et utilisera le réglage actuel (%s)."
942948

943949
msgid "Yes"
944950
msgstr "Oui"
@@ -2222,10 +2228,10 @@ msgstr "Effacer l'espace de travail avant de charger un fichier HDF5"
22222228

22232229
msgid ""
22242230
"If enabled, the current workspace will be cleared before loading a new HDF5 file.\n"
2225-
"If disabled, imported objects' processing history will be lost (features like 'Show source' and 'Recompute' will not work) because object identifiers will be regenerated to avoid conflicts."
2231+
"If disabled, when importing DataLab workspace files, only objects with conflicting identifiers will have their processing history lost (features like 'Show source' and 'Recompute' will not work for those objects). Non-conflicting objects will preserve their processing history."
22262232
msgstr ""
22272233
"Si activé, l'espace de travail actuel sera effacé avant de charger un nouveau fichier HDF5.\n"
2228-
"Si désactivé, l'historique de traitement des objets importés sera perdu (des fonctionnalités telles que 'Afficher la source' et 'Recalculer' ne fonctionneront pas) car les identifiants d'objet seront régénérés pour éviter les conflits."
2234+
"Si désactivé, lors de l'importation de fichiers de l'espace de travail DataLab, seuls les objets avec des identifiants en conflit perdront leur historique de traitement (les fonctionnalités telles que 'Afficher la source' et 'Retraiter' ne fonctionneront pas pour ces objets). Les objets non conflictuels conserveront leur historique de traitement."
22292235

22302236
msgid "Ask before clearing workspace"
22312237
msgstr "Demander avant d'effacer l'espace de travail"

datalab/objectmodel.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,17 @@ def __contains__(self, obj: SignalObj | ImageObj) -> bool:
247247
"""Return True if obj is in model"""
248248
return get_uuid(obj) in self._objects
249249

250+
def has_uuid(self, uuid: str) -> bool:
251+
"""Check if an object with the given UUID exists in the model
252+
253+
Args:
254+
uuid: UUID string to check
255+
256+
Returns:
257+
True if an object with this UUID exists, False otherwise
258+
"""
259+
return uuid in self._objects
260+
250261
def clear(self) -> None:
251262
"""Clear model"""
252263
self._objects.clear()

datalab/tests/features/common/uuid_preservation_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_uuid_preservation_images():
163163

164164

165165
def test_uuid_regeneration_on_import():
166-
"""Test that UUIDs are regenerated when importing (not resetting workspace)"""
166+
"""Test that UUIDs are regenerated only when conflicts exist during import"""
167167
with qt_app_context():
168168
with helpers.WorkdirRestoringTempDir() as tmpdir:
169169
with datalab_test_app_context(console=False) as win:
@@ -178,7 +178,7 @@ def test_uuid_regeneration_on_import():
178178
win.save_to_h5_file(fname)
179179

180180
# Step 2: Import the same file (reset_all=False, import_all=True)
181-
# This should regenerate UUIDs to avoid conflicts
181+
# This should regenerate UUID only for the conflicting object
182182
win.open_h5_files([fname], import_all=True, reset_all=False)
183183

184184
# Step 3: Verify we now have 2 signals with different UUIDs

0 commit comments

Comments
 (0)