Repository: spdx/tools-python

Issue:
Valid SPDX cannot be converted from JSON to tag:value
[bug.spdx.json](https://github.com/spdx/tools-python/files/13452674/bug.spdx.json)

File ```bug.spdx.json```is valid SPDX:
```
pyspdxtools -i bug.spdx.json
```

But it cannot be converted to tag:value:
```
pyspdxtools -i bug.spdx.json -o bug.spdx
Traceback (most recent call last):
  File "/opt/homebrew/bin/pyspdxtools", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/spdx_tools/spdx/clitools/pyspdxtools.py", line 96, in main
    write_file(document, outfile, validate=False)
  File "/opt/homebrew/lib/python3.11/site-packages/spdx_tools/spdx/writer/write_anything.py", line 22, in write_file
    tagvalue_writer.write_document_to_file(document, file_name, validate)
  File "/opt/homebrew/lib/python3.11/site-packages/spdx_tools/spdx/writer/tagvalue/tagvalue_writer.py", line 39, in write_document_to_file
    write_document_to_stream(document, out, validate, drop_duplicates)
  File "/opt/homebrew/lib/python3.11/site-packages/spdx_tools/spdx/writer/tagvalue/tagvalue_writer.py", line 34, in write_document_to_stream
    write_document(document, stream)
  File "/opt/homebrew/lib/python3.11/site-packages/spdx_tools/spdx/writer/tagvalue/tagvalue_writer.py", line 43, in write_document
    relationships_to_write, contained_files_by_package_id = scan_relationships(
                                                            ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/spdx_tools/spdx/writer/tagvalue/tagvalue_writer_helper_functions.py", line 89, in scan_relationships
    and relationship.related_spdx_element_id in files_by_spdx_id.keys()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'SpdxNoAssertion'
```


Comments:

Patch:
diff --git a/src/spdx_tools/spdx/writer/tagvalue/tagvalue_writer_helper_functions.py b/src/spdx_tools/spdx/writer/tagvalue/tagvalue_writer_helper_functions.py
index 907c155..98f6702 100644
--- a/src/spdx_tools/spdx/writer/tagvalue/tagvalue_writer_helper_functions.py
+++ b/src/spdx_tools/spdx/writer/tagvalue/tagvalue_writer_helper_functions.py
@@ -83,7 +83,9 @@ def scan_relationships(
     files_by_spdx_id = {file.spdx_id: file for file in files}
     packages_spdx_ids = [package.spdx_id for package in packages]
     for relationship in relationships:
-        if (
+        if relationship.related_spdx_element_id in [SpdxNoAssertion(), SpdxNone()]:
+            relationships_to_write.append(relationship)
+        elif (
             relationship.relationship_type == RelationshipType.CONTAINS
             and relationship.spdx_element_id in packages_spdx_ids
             and relationship.related_spdx_element_id in files_by_spdx_id.keys()


Test patch:
diff --git a/tests/spdx/writer/tagvalue/test_tagvalue_writer_helper_functions.py b/tests/spdx/writer/tagvalue/test_tagvalue_writer_helper_functions.py
index d101fd3..4949b43 100644
--- a/tests/spdx/writer/tagvalue/test_tagvalue_writer_helper_functions.py
+++ b/tests/spdx/writer/tagvalue/test_tagvalue_writer_helper_functions.py
@@ -5,7 +5,7 @@ from unittest.mock import MagicMock, call, mock_open, patch
 
 import pytest
 
-from spdx_tools.spdx.model import ActorType, RelationshipType, SpdxNoAssertion
+from spdx_tools.spdx.model import ActorType, RelationshipType, SpdxNoAssertion, SpdxNone
 from spdx_tools.spdx.writer.tagvalue.tagvalue_writer_helper_functions import scan_relationships, write_actor
 from tests.spdx.fixtures import actor_fixture, file_fixture, package_fixture, relationship_fixture
 
@@ -16,6 +16,18 @@ def test_scan_relationships():
     packages = [package_fixture(spdx_id=first_package_spdx_id), package_fixture(spdx_id=second_package_spdx_id)]
     file_spdx_id = "SPDXRef-File"
     files = [file_fixture(spdx_id=file_spdx_id)]
+    no_assertion_relationship = relationship_fixture(
+        spdx_element_id=second_package_spdx_id,
+        relationship_type=RelationshipType.CONTAINS,
+        related_spdx_element_id=SpdxNoAssertion(),
+        comment=None,
+    )
+    none_relationship = relationship_fixture(
+        spdx_element_id=second_package_spdx_id,
+        relationship_type=RelationshipType.CONTAINS,
+        related_spdx_element_id=SpdxNone(),
+        comment=None,
+    )
     relationships = [
         relationship_fixture(
             spdx_element_id=first_package_spdx_id,
@@ -29,11 +41,13 @@ def test_scan_relationships():
             related_spdx_element_id=file_spdx_id,
             comment=None,
         ),
+        no_assertion_relationship,
+        none_relationship,
     ]
 
     relationships_to_write, contained_files_by_package_id = scan_relationships(relationships, packages, files)
 
-    assert relationships_to_write == []
+    assert relationships_to_write == [no_assertion_relationship, none_relationship]
     assert contained_files_by_package_id == {first_package_spdx_id: files, second_package_spdx_id: files}