From 07a3efb4ef6bbde9eb5c407245d091873d752816 Mon Sep 17 00:00:00 2001
From: Philipp Schmidt <philipp.schmidt@xfel.eu>
Date: Tue, 1 Nov 2022 15:29:27 +0100
Subject: [PATCH] Add placeholder values for non-existing METADATA entries in
 old files

---
 src/cal_tools/files.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/cal_tools/files.py b/src/cal_tools/files.py
index 9d18d72de..5d1900441 100644
--- a/src/cal_tools/files.py
+++ b/src/cal_tools/files.py
@@ -259,7 +259,7 @@ class DataFile(h5py.File):
 
     def create_metadata(self, like=None, *,
                         creation_date=None, update_date=None, proposal=0,
-                        run=None, sequence=None, daq_library='1.x',
+                        run=0, sequence=None, daq_library='1.x',
                         karabo_framework='2.x', control_sources=(),
                         instrument_channels=()):
         """Create METADATA datasets.
@@ -297,10 +297,11 @@ class DataFile(h5py.File):
 
         if like is not None:
             metadata = like.run_metadata()
-            proposal = metadata['proposalNumber']
-            run = metadata['runNumber']
-            daq_library = metadata['daqLibrary']
-            karabo_framework = metadata['karaboFramework']
+            proposal = metadata.get('proposalNumber', proposal)
+            run = metadata.get('runNumber', run)
+            daq_library = metadata.get('daqLibrary', daq_library)
+            karabo_framework = metadata.get('karaboFramework',
+                                            karabo_framework)
 
         else:
             if run is None:
-- 
GitLab