python-pyodata icon indicating copy to clipboard operation
python-pyodata copied to clipboard

the method select of ODataQuery classes should handle iterable parameters

Open amosang opened this issue 6 years ago • 5 comments

The generated URL for $select is faulty for a list of properties, and only gives the last property specified. Please see attached Word document for details. Problem with generated $select HTTP parameter.docx

amosang avatar Oct 24 '19 11:10 amosang

It should be easy to fix but I want to refactor the code to avoid duplication. Until we fix this, could you pass str instead of list, please?

.select(','.join(['Bukrs', 'Recntype', 'Recntxt'])

PS: Would it be possible to stop communicating via Word and screenshots? I do not have MS Office and screenshots do not allow searching and copying. GitHub allows you to format issues and include pictures (I don't ask for them, I just state it is possible) - https://help.github.com/en/github/writing-on-github/basic-writing-and-formatting-syntax

filak-sap avatar Oct 24 '19 15:10 filak-sap

Developer notes:

     def select(self, select):
         """Sets the selection clauses."""
-        self._select = select
+        if isinstance(select, str):
+            self._select = select
+        elif isinstance(select, (list, tuple, set)):
+            self._select = ','.join(select)
+

but we have 2 selects:

  • class QueryRequest
  • class EntityGetRequest

filak-sap avatar Oct 24 '19 15:10 filak-sap

Event smarter solution would be:

-    def select(self, select):
+    def select(self, *select):
         """Sets the selection clauses."""
-        self._select = select
+        if not select or select[0] is None:
+            self._select = None
+            return
+
+        for i, select_member in enumerate(select):
+            if isinstance(select, (list, tuple, set)):
+                select[i] = ','.join(select_member)
+
+        self._select = ','.join(select)
+
         return self

filak-sap avatar Oct 24 '19 15:10 filak-sap

Thanks for the prompt response, Jakub. Before we forget, would like to add that it would be good to handle select=* too, as per the OData protocol.

Example: http://dffes01.h800.local:8000/sap/opu/odata/sap/RE_CN_CONTRACT_ODATA_SRV/ContractDataSet(Bukrs='1001',Recnnr='31000242')?select=*

amosang avatar Oct 29 '19 01:10 amosang

@amosang Good catch. Could you file a new issue, please?

filak-sap avatar Oct 29 '19 07:10 filak-sap