Repository: dag-hammarskjold-library/dlx

Issue:
Add default 000 to MRK serialization
https://github.com/dag-hammarskjold-library/dlx-rest/issues/1682

Hints from issue comments:

Solution patch:
diff --git a/dlx/marc/__init__.py b/dlx/marc/__init__.py
index b9c4741..f081cb4 100644
--- a/dlx/marc/__init__.py
+++ b/dlx/marc/__init__.py
@@ -1390,6 +1390,9 @@ def to_mrk(self, *tags, language=None, write_id=True):
 
         if write_id and record.id is not None:
             record.set('001', None, str(record.id))
+
+        if not record.get_value('000'):
+            record.set('000', 'None', '****')
         
         return '\n'.join([field.to_mrk(language=language) for field in record.get_fields()]) + '\n'
 


Test patch:
diff --git a/tests/test_marc.py b/tests/test_marc.py
index e67a4f4..efb534a 100644
--- a/tests/test_marc.py
+++ b/tests/test_marc.py
@@ -778,6 +778,10 @@ def test_to_mrk(bibs):
     control = '\n'.join([line for line in control.split("\n") if line[:4] != '=001'])
     assert bib.to_mrk(write_id=False) == control
 
+    # add 000 if not exists
+    bib = Bib().set('245', 'a', 'title')
+    assert bib.to_mrk() == '=000  ****\n=245  \\\\$atitle\n'
+
 def test_from_mrk(db):
     from dlx.marc import Bib