added deprecation notices to older-style methods#128
Conversation
sujen1412
left a comment
There was a problem hiding this comment.
Requested changes for python client to raise a warning and not an HTTP code which is incorrect here since the HTTP method is not gone.
If we want to raise an error there should a be a true Exception being raised and not have the function return succesfully and the error is hidden in the json
| def searchGranule(self): | ||
| """ | ||
| Search for granules in the CMR (Common Metadata Repository). | ||
|
|
||
| Queries the CMR database for granules matching the specified criteria. | ||
| Granules represent individual data files within a collection. | ||
|
|
||
| DEPRECATION NOTICE: This method is no longer supported. Use the following instead: | ||
|
|
||
| search_granule(limit=20, **kwargs) | ||
|
|
||
| limit : int, optional | ||
| Maximum number of results to return. Default is 20. | ||
| **kwargs : dict | ||
| Search parameters to filter results. Common parameters include: | ||
|
|
||
| """ | ||
| response = requests.Response() | ||
| response.status_code = 410 | ||
| response._content = json.dumps({ | ||
| "message": "searchGranule() is no longer supported. Use search_granule(limit=20, **kwargs) instead." | ||
| }).encode('utf-8') | ||
| response.headers['Content-Type'] = 'application/json' | ||
| return response |
There was a problem hiding this comment.
This code snippet will not give a warning to the caller instead give a hidden error message in the json with an HTTP code which is not relevant in a python function being deprecated.
One way to give warning would be show a warning message and not an error.
| def searchGranule(self): | |
| """ | |
| Search for granules in the CMR (Common Metadata Repository). | |
| Queries the CMR database for granules matching the specified criteria. | |
| Granules represent individual data files within a collection. | |
| DEPRECATION NOTICE: This method is no longer supported. Use the following instead: | |
| search_granule(limit=20, **kwargs) | |
| limit : int, optional | |
| Maximum number of results to return. Default is 20. | |
| **kwargs : dict | |
| Search parameters to filter results. Common parameters include: | |
| """ | |
| response = requests.Response() | |
| response.status_code = 410 | |
| response._content = json.dumps({ | |
| "message": "searchGranule() is no longer supported. Use search_granule(limit=20, **kwargs) instead." | |
| }).encode('utf-8') | |
| response.headers['Content-Type'] = 'application/json' | |
| return response | |
| def searchGranule(self, limit, **kwargs): | |
| """ | |
| Deprecated: use search_granule() instead. | |
| """ | |
| warnings.warn( | |
| "searchGranule() is deprecated and will be removed in a future version. " | |
| "Use search_granule(limit=20, **kwargs) instead.", | |
| DeprecationWarning, | |
| stacklevel=2 | |
| ) | |
| return self.search_granule(*args, **kwargs) |
If we want to users to stop using that method and know that the method is no longer supported.
| def searchGranule(self): | |
| """ | |
| Search for granules in the CMR (Common Metadata Repository). | |
| Queries the CMR database for granules matching the specified criteria. | |
| Granules represent individual data files within a collection. | |
| DEPRECATION NOTICE: This method is no longer supported. Use the following instead: | |
| search_granule(limit=20, **kwargs) | |
| limit : int, optional | |
| Maximum number of results to return. Default is 20. | |
| **kwargs : dict | |
| Search parameters to filter results. Common parameters include: | |
| """ | |
| response = requests.Response() | |
| response.status_code = 410 | |
| response._content = json.dumps({ | |
| "message": "searchGranule() is no longer supported. Use search_granule(limit=20, **kwargs) instead." | |
| }).encode('utf-8') | |
| response.headers['Content-Type'] = 'application/json' | |
| return response | |
| def searchGranule(self, *args, **kwargs): | |
| raise NotImplementedError( | |
| "searchGranule() has been removed. " | |
| "Use search_granule(limit=20, **kwargs) instead." | |
| ) |
An HTTP code is wrong in this case as maap-py is a python client and not code for an API.
sujen1412
left a comment
There was a problem hiding this comment.
Approved with note that raising better exceptions is coming in the next feature update.
Preparatory work in support of the transition to OGC.
Closes #1299