Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
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"
}
โ
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.
Hi, don't use **kwargs or *args, just use standard function parameters:
#Code
def api_py_function(param1):
return param1
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'
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.
What Dataiku version are you on?
12.2
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:
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.