Repository: SAP/python-pyodata

Issue:
Expanded properties don't have their own results wrapper in V2 like this library expects
In OData V2 JSON, expanded properties are simple arrays of the contained entities. 

See https://www.odata.org/documentation/odata-version-2-0/json-format/
Section 9, 9. Inline Representation of Associated Entries

However, pyodata expects the nested entities to be wrapped in a results object: 

https://github.com/SAP/python-pyodata/blob/ea558f504532e378e182952db5e78aead3d23a6e/tests/test_service_v2.py#L1492C18-L1492C25
https://github.com/SAP/python-pyodata/blob/ea558f504532e378e182952db5e78aead3d23a6e/pyodata/v2/service.py#L875C31-L875C31

This is not according to spec and will fail with common implementations (including SAP service providers) as in  the expanded property will discard the array received from the service and will default to an empty list. 

Discussion:
cla-assistant[bot]: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/SAP/python-pyodata?pullRequest=259) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/SAP/python-pyodata?pullRequest=259) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/SAP/python-pyodata?pullRequest=259) it.</sub>
phanak-sap: Simple, yet backward compatible fix with necessary changes of test suite. Perfect. Thanks  @manuelseeger 

Patch:
diff --git a/pyodata/v2/service.py b/pyodata/v2/service.py
index 0da3463..e84d2f7 100644
--- a/pyodata/v2/service.py
+++ b/pyodata/v2/service.py
@@ -873,10 +873,12 @@ class EntityProxy:
                         # if there are no entities available, received data consists of
                         # metadata properties only.
                         if 'results' in proprties[prop.name]:
-
                             # available entities are serialized in results array
                             for entity in proprties[prop.name]['results']:
                                 self._cache[prop.name].append(EntityProxy(service, None, prop_etype, entity))
+                        else:
+                            for entity in proprties[prop.name]:
+                                self._cache[prop.name].append(EntityProxy(service, None, prop_etype, entity))
                     else:
                         raise PyODataException('Unknown multiplicity {0} of association role {1}'
                                                .format(prop.to_role.multiplicity, prop.to_role.name))


Test patch:
diff --git a/tests/test_service_v2.py b/tests/test_service_v2.py
index 7c70513..bc4e0e3 100644
--- a/tests/test_service_v2.py
+++ b/tests/test_service_v2.py
@@ -1476,7 +1476,7 @@ def test_get_entity_not_encoded_path(service):
 
 
 @responses.activate
-def test_get_entity_expanded(service):
+def test_get_entity_expanded_with_results(service):
     """Check getting entities with expanded navigation properties"""
 
     # pylint: disable=redefined-outer-name
@@ -1513,6 +1513,42 @@ def test_get_entity_expanded(service):
     assert emp.Addresses[0].Street == 'Baker Street'
     assert emp.Addresses[0].City == 'London'
 
+@responses.activate
+def test_get_entity_expanded(service):
+    """Check getting entities with expanded navigation properties"""
+
+    # pylint: disable=redefined-outer-name
+    path = quote("Employees(23)")
+    responses.add(
+        responses.GET,
+        f"{service.url}/{path}",
+        json={'d': {
+            'ID': 23,
+            'NameFirst': 'Rob',
+            'NameLast': 'Ickes',
+            'Addresses': [
+                    {
+                        'ID': 456,
+                        'Street': 'Baker Street',
+                        'City': 'London'
+                    }
+                ]
+            
+        }},
+        status=200)
+
+    request = service.entity_sets.Employees.get_entity(23)
+    assert isinstance(request, pyodata.v2.service.EntityGetRequest)
+
+    emp = request.expand('Addresses').execute()
+
+    assert emp.ID == 23
+    assert emp.NameFirst == 'Rob'
+    assert emp.NameLast == 'Ickes'
+
+    assert emp.Addresses[0].ID == 456
+    assert emp.Addresses[0].Street == 'Baker Street'
+    assert emp.Addresses[0].City == 'London'
 
 @responses.activate
 def test_batch_request(service):