Skip to content

sdk: python: Pass objects instead of IDs - #3870

Merged
gerhard merged 1 commit into
dagger:mainfrom
helderco:python/hide-ids
Nov 16, 2022
Merged

gerhard merged 1 commit into
dagger:mainfrom
helderco:python/hide-ids

Conversation

@helderco

Copy link
Copy Markdown
Contributor

Fixes #3690

Python’s implementation of #3558

Before

pip_cache_id = await client.cache_volume(pip_cache_key).id()
venv_cache_id = await client.cache_volume(venv_cache_key).id()

container = (
    client.container()
    .from_("python:slim")
    .with_mounted_cache("/root/.cache/pip", pip_cache_id)
    .with_mounted_cache("/opt/venv", venv_cache_id)
)

out = await container.exec(["pip", "list"]).stdout().contents()

After

container = (
    client.container()
    .from_("python:slim")
    .with_mounted_cache("/root/.cache/pip", client.cache_volume(pip_cache_key))
    .with_mounted_cache("/opt/venv", client.cache_volume(venv_cache_key))
)

out = await container.exec(["pip", "list"]).stdout().contents()

Sync

Sync is also supported but there’s a performance benefit with async because all id fields get resolved concurrently before executing the main query. So even though you may only have one await and doesn’t seem like there’s benefit, it’s not the case.

Signed-off-by: Helder Correia

Fields named `id` aren’t converted.

Async mode has a performance benefit because all id fields are resolved concurrently before executing the main query.

Had a lingering issue where the linter was ignoring the generated files because of long docstrings from the API so I fixed it as well.

Signed-off-by: Helder Correia <[email protected]>

@gerhard gerhard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very nice improvement @helderco! Ready to 🛫


Nit: I noticed the skipped test. I would either remove it or fix it soon.

@gerhard
gerhard merged commit 10e89ac into dagger:main Nov 16, 2022
@helderco

Copy link
Copy Markdown
Contributor Author

Which skipped test?

@helderco
helderco deleted the python/hide-ids branch November 16, 2022 15:48
@helderco

Copy link
Copy Markdown
Contributor Author

@gerhard I realize you must mean the docker provisioning test which doesn't run on dagger-in-dagger. More context here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/breaking Breaking Change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hide IDs in API client

2 participants