-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BugFix] - Untyped variadic keyword arguments break during execution #6250
Conversation
I still get the same error,
We very much need this in PackageBuilder:
We still need changes in CommandRunner:
There are two things that happen in my proposed changes to CommandRunner:
|
if parameter.name == "cc" and parameter.annotation == CommandContext: | ||
continue | ||
|
||
if parameter.kind == Parameter.VAR_KEYWORD: | ||
var_kw_start = pos | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"kwargs" is being forced as a "required" field in the body, and calling it VAR_KEYWORD or VAR_POSITIONAL is not allowed with a default value. Optional[Dict]
is not actually optional without a default state. Setting as POSITIONAL_OR_KEYWORD allows you to set a default value of {}, and **kwargs is still in the request body.
It would be ideal if you didn't have to put kwargs in the body, but could just add them to the URL like every other parameter. This behaviour, though, is limited to the API. The Python interface does not require them to be declared within the field "kwargs".
if parameter.name == "kwargs":
new_parameter_list.append(
Parameter(
parameter.name,
kind=parameter.POSITIONAL_OR_KEYWORD,
annotation=Optional[Dict[str, Any]],
default={},
)
)
else:
new_parameter_list.append(
Parameter(
parameter.name,
kind=parameter.kind,
default=parameter.default,
annotation=parameter.annotation,
)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not possible to add undefined URL parameters to API endpoints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well then we can't get around that "nice to have" thing, but at least they can be unpacked the same as the Python interface.
This: body = json.dumps({"data": data, "kwargs": {"chart_params": {"title": "my chart"}}})
When unpacked becomes the same as the Python Interface "extras":
{'metadata': {'arguments': {'index': 'date',
'lower_q': 0.25,
'upper_q': 0.75,
'model': 'std',
'is_crypto': False,
'trading_periods': None,
'data': {'type': 'List[Data]',
'columns': ['open',
'vwap',
'split_ratio',
'close',
'volume',
'dividend',
'date',
'low',
'high']},
'chart_params': {'title': 'my chart'}},
'duration': 109062167,
'route': '/technical/cones',
'timestamp': '2024-03-22T12:05:53.906124'}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metadata reflects the call that was made to the api, if the call sends 'chart_params': {'title': 'my chart'}}
inside a parameter called kwargs
/some_kw_args
/extra_params
it is expected that you see
{'metadata':
{'arguments':
{
'index': 'date',
'lower_q': 0.25,
'data': {
'type': 'List[Data]',
'columns': ['open', ...],
},
'kwargs/some_kw_args/extra_params': {'chart_params': {'title': 'my chart'}}
},
'duration': 109062167,
'route': '/technical/cones',
'timestamp': '2024-03-22T12:05:53.906124'}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this purpose, "extra_params" is a better name for this than "kwargs". Less confusion with everything else that is passed around as "kwargs".
I get an error when no kwargs are supplied to the POST request:
|
thanks, |
Why?
VAR_KEYORD
arguments in endpoints like**kwargs
are not supportedextra_params
is raising by mistake wheneverextra_params
existsWhat?
extra_params
is of typeExtraParams
validate_kwargs
allows untyped arguments like**kwargs
to pass validation asAny
VAR_KEYWORD
arguments always come lastVAR_KEYWORD
argument names to any name and makes sure they always come lastImpact
VAR_KEYWORD
parameters (**kwargs
) in the endpoints, although this is has some non obvious caveats in the API - it will make theVAR_KEYWORD
a required URL parameter, since**
parameters cannot have a default, thus FastAPI sees it as required. Will be on the developer side if this is good for the use case or not.Testing Done:
extra_params: Optional[Dict] = None
to anyPOST
method, rebuild, run commands or make API calls**any_arg
to an endpoint and run commands or make API calls