Repository: LeMyst/WikibaseIntegrator

Issue:
This seems wrong. What if I modify a Lexeme?
https://github.com/LeMyst/WikibaseIntegrator/blob/30c2f766931f442a2ec7160073331811859a840d/wikibaseintegrator/wbi_core.py#L905
Wouldn't it return the LID then?

Discussion:

Patch:
diff --git a/wikibaseintegrator/wbi_core.py b/wikibaseintegrator/wbi_core.py
index 1fdf93a..d9bebb5 100644
--- a/wikibaseintegrator/wbi_core.py
+++ b/wikibaseintegrator/wbi_core.py
@@ -37,7 +37,7 @@ class ItemEngine(object):
         :type new_item: True or False
         :param data: a dictionary with property strings as keys and the data which should be written to a item as the
             property values
-        :type data: List[BaseDataType]
+        :type data: List[BaseDataType] or BaseDataType
         :param append_value: a list of properties where potential existing values should not be overwritten by the data
             passed in the :parameter data.
         :type append_value: list of property number strings
@@ -109,7 +109,14 @@ class ItemEngine(object):
             'PROPERTY_CONSTRAINT_PID'] if property_constraint_pid is None else property_constraint_pid
         self.distinct_values_constraint_qid = config[
             'DISTINCT_VALUES_CONSTRAINT_QID'] if distinct_values_constraint_qid is None else distinct_values_constraint_qid
-        self.data = [] if data is None else data
+        if data is None:
+            self.data = []
+        elif isinstance(data, BaseDataType):
+            self.data = [data]
+        elif not isinstance(data, list):
+            raise TypeError("data must be a list or an instance of BaseDataType")
+        else:
+            self.data = data
         self.append_value = [] if append_value is None else append_value
         self.fast_run = fast_run
         self.fast_run_base_filter = fast_run_base_filter
@@ -757,7 +764,7 @@ class ItemEngine(object):
         lang = config['DEFAULT_LANGUAGE'] if lang is None else lang
 
         if not isinstance(aliases, list):
-            raise ValueError('aliases must be a list')
+            raise TypeError('aliases must be a list')
 
         if if_exists != 'APPEND' and if_exists != 'REPLACE':
             raise ValueError('{} is not a valid value for if_exists (REPLACE or APPEND)'.format(if_exists))
@@ -902,7 +909,7 @@ class ItemEngine(object):
         :type max_retries: int
         :param retry_after: Number of seconds to wait before retrying request (see max_retries)
         :type retry_after: int
-        :return: the QID on sucessful write
+        :return: the entity ID on successful write
         """
 
         if self.search_only:


Test patch:
diff --git a/wikibaseintegrator/tests/test_item_creation.py b/wikibaseintegrator/tests/test_item_creation.py
index 7f7bf40..31fe271 100644
--- a/wikibaseintegrator/tests/test_item_creation.py
+++ b/wikibaseintegrator/tests/test_item_creation.py
@@ -39,8 +39,12 @@ class TestItemCreation(unittest.TestCase):
         for d in data:
             item = wbi_core.ItemEngine(new_item=True, data=[d], core_props=core_props)
             assert item.get_json_representation()
+            item = wbi_core.ItemEngine(new_item=True, data=d, core_props=core_props)
+            assert item.get_json_representation()
             item = wbi_core.ItemEngine(new_item=True, data=[d], core_props=set())
             assert item.get_json_representation()
+            item = wbi_core.ItemEngine(new_item=True, data=d, core_props=set())
+            assert item.get_json_representation()
 
         item = wbi_core.ItemEngine(new_item=True, data=data, core_props=core_props)
         assert item.get_json_representation()