Comments (2)
Note that the suggested workaround of clicking omit value
on the optional parameter is not viable in our case. Accidentally sending the (unwanted) default value False
could have huge consequences. For now we work around this by explicitly using the default value True
but we'd rather have an explicitly optional value.
Another suggestion was to use a dropdown, maybe something. like Literal['true', 'false'] | None
. However, that would require a redundant pydantic BaseModel for the UI vs internal representation.
from prefect.
hello @martin-schulze-e2m - I can reproduce this only with pydantic<2
from prefect import flow
@flow(log_prints=True)
def optional_bool(x: bool | None = None) -> bool:
print(x)
if __name__ == "__main__":
optional_bool.serve("optional-bool")
with pydantic==1.x
ยป prefect deployment inspect optional-bool/optional-bool
{
"parameter_openapi_schema": {
"type": "object",
"title": "Parameters",
"properties": {
"x": {
"type": "boolean",
"title": "x",
"position": 0
}
}
}
}
with pydantic
2.x
{
"parameter_openapi_schema": {
"type": "object",
"title": "Parameters",
"properties": {
"x": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"title": "x",
"default": null,
"position": 0
}
}
}
a bool toggle seems like the correct thing for the UI to render in the case of the OpenAPI schema resulting from the pydantic 1 case. It seems like this is a limitation of the way pydantic 1 dumps Optional
types into an OpenAPI schema.
if you're stuck on pydantic 1, how is this for a workaround?
from pydantic import BaseModel
from prefect import flow
class noop(BaseModel):
"""A class that does nothing"""
@flow(log_prints=True)
def optional_bool(x: bool | noop = noop()):
print(x)
if __name__ == "__main__":
optional_bool.serve("optional-bool")
pydantic 2 behavior
If I use Custom Run
I see this as expected:
and in either case, I see null
passed to the flow run as expected
from prefect.
Related Issues (20)
- Add integrations test for `.deploy()`
- prefect-dbt: from_file method for PostgresTargetConfig
- prefect-dbt: from_file method for SnowflakeTargetConfigs
- prefect-dbt: from_file method for BigQueryTargetConfigs
- prefect-dbt: from_file method for TargetConfigs
- Prefect Markdown Artifacts: pass in a existing Markdown file or Jinja template
- Make `Task.serve` a sync-compatible coroutine
- Complete missing Task.submit() docstring sentence HOT 1
- Create a `PrefectDistributedFuture` to submit and track runs in task servers HOT 1
- Attempting to deploy with DeploymentImage results in "RuntimeError: This error is often thrown because Docker is not running." HOT 5
- docker storage deployment randomly fails `No such file or directory` HOT 2
- DBT integration not working with GCP application default credentials using SA impersonation
- Deployment Issues with from_source using LocalFileSystem Block HOT 6
- Add a `Task.defer` method HOT 1
- Calling `task_a.submit(task_b.submit())` should fail with an informative error with autonomous tasks
- MattermostWebhook does not send message to https server HOT 1
- Ensure infrastructure is always killed when job has crashed
- .serve() truncates a deployment name with two dots HOT 2
- Purge old Dask futures when no longer needed HOT 1
- `/create_flow_run` doesn't hydrate workspace variables HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prefect.