Repository navigation
Description
A tangential issue I noticed during some adventures with #7767
At least in the Go SDK, the generated Sync method will just return the query it has built so far, e.g.
Lines 2102 to 2106 in adca4e6
| func (r *Directory) Sync(ctx context.Context) (*Directory, error) { | |
| q := r.query.Select("sync") | |
| return r, q.Execute(ctx) | |
| } |
However, this does not play nicely with our core APIs that rely on returning a dagql.Instance of a different API call, e.g.
Lines 63 to 69 in adca4e6
| func (host *Host) Directory( | |
| ctx context.Context, | |
| srv *dagql.Server, | |
| dirPath string, | |
| pipelineNamePrefix string, | |
| filter CopyFilter, | |
| ) (dagql.Instance[*Directory], error) { |
While Sync is correctly called, the SDK doesn't use the returned ID and instead uses the query it already built up.
This is especially wrong in the case of impure APIs, since it will result in the API being repeatedly called incorrectly with the "original" ID.
- e.g. if the query is to load a local dir and sync is called, then any subsequent calls on the returned Directory will re-run the load of the local dir.
In terms of the practical impact today, not 100% sure, it did break new APIs I was adding in #7767 but:
- I'm not sure if it causes significant incorrect/unperformant behavior for existing core APIs. It seems possible but would require more tracing of code and testing
- I only looked at the Go SDK so far, not sure what others are impacted if any
Activity
helderco commentedon Jun 29, 2024
It was done this way because at the time we didn't have a good way to convert any ID to its corresponding object. That changed with the
loadXFromIDfields.I left a comment in codegen, but was removed in #5881 by 7393e19#diff-de9a6011ccf4884745982bf7658dae4ec2e8d2564dd5a5b1063ef7dbe5678de7L145-L153:
helderco commentedon Jun 29, 2024
This was fixed in Python in #5353, with this change:
f799e77#diff-456e93caaf55f83fa963bff05f16413d26c0bfc01505ee73c7753b915ff22a55L403-R450
This was made possible by mapping out which fields would take an ID and return the corresponding object:
dagger/sdk/python/src/dagger/codegen.py
Lines 156 to 166 in f799e77
This logic was simplified later by #6184.
So it's easy to fix in Go and TS now, because of the new convention.
wingyplus commentedon Jun 29, 2024
I just realize that elixir return an id, not a structure to the caller. Which is definitely a bug in the codegen. I will submit a PR to fix this and make sure the api align with other sdk in 2 or 3 days.
fix(sdk/elixir): sync functions should struct not an id type
fix(sdk/elixir): sync functions should struct not an id type (#7817)