python-pyodata
python-pyodata copied to clipboard
the method select of ODataQuery classes should handle iterable parameters
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
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
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
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
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 Good catch. Could you file a new issue, please?