From 64cb563b1bfbe186fca7ef190563f4afa210103a Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Mon, 24 Apr 2023 13:51:19 +0200
Subject: [PATCH] FIX: Treat the specific case of type: [null, something]

---
 .gitlab-ci.yml                         | 2 +-
 setup.py                               | 2 +-
 src/caosadvancedtools/models/parser.py | 5 +++++
 tox.ini                                | 1 -
 4 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d6066030..80f38616 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -139,7 +139,7 @@ unittest_py37:
   stage: unittest
   image: python:3.7
   script: &python_test_script
-    - pip install nose pandas pytest pytest-cov gitignore-parser openpyxl>=3.0.7 xlrd==1.2 h5py jsonref
+    - pip install nose pandas pytest pytest-cov gitignore-parser openpyxl>=3.0.7 xlrd==1.2 h5py
     - pip install git+https://gitlab.indiscale.com/caosdb/src/caosdb-pylib.git@dev
     - pip install .
     - pytest --cov=caosadvancedtools unittests
diff --git a/setup.py b/setup.py
index eed060aa..4f4d8943 100755
--- a/setup.py
+++ b/setup.py
@@ -156,6 +156,7 @@ def setup_package():
         author_email='h.tomwoerden@indiscale.com',
         python_requires='>=3.7',
         install_requires=["caosdb>=0.11.0",
+                          "jsonref",
                           "jsonschema>=4.4.0",
                           "numpy>=1.17.3",
                           "openpyxl>=3.0.7",
@@ -164,7 +165,6 @@ def setup_package():
                           ],
         extras_require={"h5-crawler": ["h5py>=3.3.0", ],
                         "gitignore-parser": ["gitignore-parser >=0.1.0", ],
-                        "jsonref": ["jsonref", ],
                         },
         packages=find_packages('src'),
         package_dir={'': 'src'},
diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py
index abf47d03..a0da3b24 100644
--- a/src/caosadvancedtools/models/parser.py
+++ b/src/caosadvancedtools/models/parser.py
@@ -747,6 +747,11 @@ class JsonSchemaParser(Parser):
                     "be identified with CaosDB's name property."
                 )
             return None, force_list
+        # LinkAhead suports null for all types, so in the very special case of
+        # `"type": ["null", "<other_type>"]`, only consider the other type:
+        if isinstance(elt["type"], list) and len(elt["type"]) == 2 and "null" in elt["type"]:
+            elt["type"].remove("null")
+            elt["type"] = elt["type"][0]
         if "enum" in elt:
             ent = self._treat_enum(elt, name)
         elif elt["type"] in JSON_SCHEMA_ATOMIC_TYPES:
diff --git a/tox.ini b/tox.ini
index ce18fc00..0e9664c3 100644
--- a/tox.ini
+++ b/tox.ini
@@ -12,7 +12,6 @@ deps=nose
     openpyxl >= 3.0.7
     xlrd == 1.2
     h5py
-    jsonref
 commands=py.test --cov=caosadvancedtools -vv {posargs}
 
 [flake8]
-- 
GitLab