Dear Community,
Let me share my experience of writing and deploying a Cognite Function and a lesson what I learnt.
Hope this topic will save someone few hours of troubleshooting.
During Data Scientist Basics learning path Python hands-on, I found myself in weird situation when the Cognite Functions I created were perfectly running on my local, but were failing in the sandbox environment after being deployed.
Here were the error log:
==================================================
- 2023-04-27 10:42 Function started
- The function terminated unexpectedly. Please contact Cognite support if the problem persists.
- _point.py", line 455, in run_handle
- result = handle(*function_argument_values)
- File "/home/site/wwwroot/function/handler.py",
line 41, in handle
- df = client.datapoints.retrieve_dataframe(
AttributeError: 'CogniteClient' object has no attribute 'datapoints'
- 2023-04-27 10:43 Function ended
==================================================
Troubleshooting doc didn’t have the error I was facing https://docs.cognite.com/cdf/functions/known_issues/
Thanks to the
Solution. I didn’t want to change the code because tomorrow another new version of SDK may break everything again. So the only way we could protect ourselves from potential future server SDK upgrade is setting the exact SDK version in requirements.txt. This approach will make your function robust and save from future headache. Same goes for the rest of the packages you use.

Suggestion. I hope that the Cognite Functions Known Issues documentation could be updated and this case will be added as well.
Thank you!