Exposed Python Function as an API not passing parameters from test query

Solved!
samanthamarkley
Level 2
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"
}

 

Screenshot 2023-11-22 at 3.15.36 PM.png

โ€ƒ

0 Kudos
1 Solution
fsergot
Dataiker

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.

View solution in original post

8 Replies
Turribeach

Hi, don't use **kwargs or *args, just use standard function parameters:

#Code
def api_py_function(param1):
    return param1

 

0 Kudos
samanthamarkley
Level 2
Author

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'

0 Kudos

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.

0 Kudos
samanthamarkley
Level 2
Author

Yes that update was also made

0 Kudos

What Dataiku version are you on?

0 Kudos
samanthamarkley
Level 2
Author

12.2

0 Kudos

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:

Screenshot 2023-11-22 at 21.24.56.png

 

 

 

 

 

0 Kudos
fsergot
Dataiker

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.

Labels

?
Labels (2)
A banner prompting to get Dataiku