Repository navigation
Description
Background
With #6359, If the last argument in dagger call is a Container, Directory, or File, the sync field is selected automatically, while the returned ID is ignored (not printed to screen). You can, however, select sync explicitly, in which case the ID is printed.
Motivation
For consistency, we want to just do the forced evaluation, without printing the returned ID to the user because there’s no meaning in this context. However, we don’t want to exclude printing all IDs because there may be some use cases for it:
Rationale
We already select sync automatically if the chain ends in an object that supports it because it makes sense as a default1. Supporting the use of sync explicitly adds redundancy and extra work if we don’t want to print the resulting ID:
- TypeDefKind doesn’t support scalars at the moment, so when looking at the type definition from an explicit
sync, it’s a string. In other words, it doesn’t have a “name” associated with it. - The query builder doesn’t have public access to the last selection. We can easily expose the name, but it would also match a user function named sync, which could have any return type.
- We could try tracking more information while building the command structure from the arguments, such that if the last selection is
sync, we could check if it’s from the core object types and not a user function.
It’s just simpler to skip creating sync as a sub-command when the parent object is a core type:
- There’s less to type
- Implementation is trivial
- You don’t have to explain the redundancy
- You still have access to
sync. It's implicit but there's a rule and consistency to it. - It still allows users to define functions named
sync, with totally different behavior, or even replicating the same behavior (by returning the result ofsyncfrom a core type).
After interfaces support in core types, rather than explicitly handle the current 3 core types that implement sync by name, we can generalize with the interface and keep the behavior consistent.
Drawback
If a user wants to use a function that returns a core type, and there’s a valid use case for needing the id, they need to jump through a hoop and get it wrapped in a user function that returns the result of sync (or id).
We can ignore that for now and revisit if the use case surfaces:
\cc @sipsma
Footnotes
-
Curiously, the Python SDK has a bit of syntax sugar where you can
awaitone of the objects directly instead of explicitly chainingsync(), for example,ctr = await src.docker_build(). ↩
Activity
helderco commentedon Jul 5, 2024
Just to update:
syncis no longer added implicitly since cli: print module object fields withdagger call#7479 but there's a follow up discussion about execution in CLI: don't run a container's default args when printing it #7821.syncbut rather than returning theContainerID, it should return the resultingContainerwithloadContainerFromID(cid).helderco commentedon Jul 6, 2024
I'm closing this in favor of: