Exposed Python Function as an API not passing parameters from test query
I am trying to test exposing a python function as an API but it seems there is a bug in the test query passing parameters to the function. The function is extremely simple and I am currently just trying to print the test parameters but it seems the query is passing through as empty. I have tried many different possible configurations of the test query syntax with no success and can not track down a clear cause from the logs. Below is the function and test query as well a screen shot of the result when run:
#Code def api_py_function(**kwargs): return kwargs #Test Query { "paramNameToReplace": "paramValueToReplace" }
Best Answer
-
There is a known bug in 12.2.0 regarding the test queries not working for custom Python endpoint (although they work fine once deployed).
This has been fixed in 12.2.2 (https://doc.dataiku.com/dss/latest/release_notes/12.html#id14)
That might your case, depending on the exact version you are using.
Answers
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,160 Neuron
Hi, don't use **kwargs or *args, just use standard function parameters:
#Code def api_py_function(param1): return param1
-
samanthamarkley Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 6 Partner
I have also tried that and receive an error message: Failed: Failed to run function : <class 'TypeError'> : api_py_function() missing 1 required positional argument: 'param1'
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,160 Neuron
The test query also needs to call the parameter param1. These are named parameters on a REST API backend, they can't be guessed by position.
-
samanthamarkley Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 6 Partner
Yes that update was also made
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,160 Neuron
What Dataiku version are you on?
-
samanthamarkley Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 6 Partner
12.2
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,160 Neuron
When you create a Python Function endpoint the function snipped is this:
# Insert here initialization code # This function is the entry point for your Python function API # You can call this function with passing "param1", "param2", # "param3" as arguments to the API call # (see REST API documentation) def api_py_function(param1, param2, param3): return param1 + param2 * param3
I then go to the Test queries and click on ADD QUERIES and add this as a test query:
{ "param1": 1, "param2": 2, "param3": 3 }
And when I test this is what I get: