status
stringclasses 1
value | repo_name
stringclasses 31
values | repo_url
stringclasses 31
values | issue_id
int64 1
104k
| title
stringlengths 4
233
| body
stringlengths 0
186k
โ | issue_url
stringlengths 38
56
| pull_url
stringlengths 37
54
| before_fix_sha
stringlengths 40
40
| after_fix_sha
stringlengths 40
40
| report_datetime
timestamp[us, tz=UTC] | language
stringclasses 5
values | commit_datetime
timestamp[us, tz=UTC] | updated_file
stringlengths 7
188
| chunk_content
stringlengths 1
1.03M
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | func New() Minimal {
return Minimal{
W: "-",
X: "-",
Y: "-",
Z: Z("-"),
}
}
// struct with no fields
type Bar struct{}
func (m *Minimal) Say(
// field with single (normal) name
a string,
// field with multiple names
b, c string,
// field with no names (not included, mixed names not allowed)
// string
) string {
return a + " " + b + " " + c
}
func (m *Minimal) Hello(
// field with no names
string,
) string {
return "hello"
}
func (m *Minimal) SayOpts(opts struct{
// field with single (normal) name
A string
// field with multiple names |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | B, C string
// field with no names (not included because of above)
// string
}) string {
return opts.A + " " + opts.B + " " + opts.C
}
func (m *Minimal) HelloOpts(opts struct{
// field with no names
string
}) string {
return "hello"
}
`,
})
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.With(daggerQuery(`{minimal{w, x, y, z}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal": {"w": "-", "x": "-", "y": "-", "z": "-"}}`, out)
for _, name := range []string{"say", "sayOpts"} {
out, err := modGen.With(daggerQuery(`{minimal{%s(a: "hello", b: "world", c: "!")}}`, name)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, fmt.Sprintf(`{"minimal": {"%s": "hello world !"}}`, name), out)
}
for _, name := range []string{"hello", "helloOpts"} {
out, err := modGen.With(daggerQuery(`{minimal{%s(string: "")}}`, name)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, fmt.Sprintf(`{"minimal": {"%s": "hello"}}`, name), out)
}
}
func TestModuleGoOptionalMustBeNil(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Minimal struct {}
func (m *Minimal) Foo(x *Optional[*string]) string {
if v, _ := x.Get(); v != nil {
panic("uh oh")
}
return ""
}
func (m *Minimal) Bar(opts struct {
x *Optional[*string]
}) string {
if v, _ := opts.x.Get(); v != nil {
panic("uh oh")
}
return ""
}
func (m *Minimal) Baz(
// +optional
x *string, |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | ) string {
if x != nil {
panic("uh oh")
}
return ""
}
func (m *Minimal) Qux(opts struct {
// +optional
x *string
}) string {
if opts.x != nil {
panic("uh oh")
}
return ""
}
`,
})
logGen(ctx, t, modGen.Directory("."))
for _, name := range []string{"foo", "bar", "baz", "qux"} {
out, err := modGen.With(daggerQuery(`{minimal{%s}}`, name)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, fmt.Sprintf(`{"minimal": {"%s": ""}}`, name), out)
}
}
func TestModuleGoFieldMustBeNil(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work"). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import "fmt"
type Minimal struct {
Src *Directory
Name *string
}
func New() *Minimal {
return &Minimal{}
}
func (m *Minimal) IsEmpty() bool {
if m.Name != nil {
panic(fmt.Sprintf("name should be nil but is %v", m.Name))
}
if m.Src != nil {
panic(fmt.Sprintf("src should be nil but is %v", m.Src))
}
return true
}
`,
})
out, err := modGen.With(daggerQuery(`{minimal{isEmpty}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal": {"isEmpty": true}}`, out)
}
func TestModulePrivateField(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
for _, tc := range []struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
}{
{
sdk: "go",
source: `package main
type Minimal struct {
Foo string |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | Bar string // +private
}
func (m *Minimal) Set(foo string, bar string) *Minimal {
m.Foo = foo
m.Bar = bar
return m
}
func (m *Minimal) Hello() string {
return m.Foo + m.Bar
}
`,
},
{
sdk: "python",
source: `from dagger import field, function, object_type
@object_type
class Minimal:
foo: str = field(default="")
bar: str = ""
@function
def set(self, foo: str, bar: str) -> "Minimal":
self.foo = foo
self.bar = bar
return self
@function
def hello(self) -> str:
return self.foo + self.bar
`,
},
} { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(inspectModule).Stdout(ctx)
require.NoError(t, err)
obj := gjson.Get(out, "host.directory.asModule.objects.0.asObject")
require.Equal(t, "Minimal", obj.Get("name").String())
require.Len(t, obj.Get(`fields`).Array(), 1)
prop := obj.Get(`fields.#(name="foo")`)
require.Equal(t, "foo", prop.Get("name").String())
out, err = modGen.With(daggerQuery(`{minimal{set(foo: "abc", bar: "xyz"){hello}}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"set":{"hello": "abcxyz"}}}`, out)
out, err = modGen.With(daggerQuery(`{minimal{set(foo: "abc", bar: "xyz"){foo}}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"minimal":{"set":{"foo": "abc"}}}`, out)
_, err = modGen.With(daggerQuery(`{minimal{set(foo: "abc", bar: "xyz"){bar}}}`)).Stdout(ctx)
require.ErrorContains(t, err, `Cannot query field "bar"`)
})
}
}
func TestModuleGoExtendCore(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
var logs safeBuffer
c, ctx := connect(t, dagger.WithLogOutput(&logs))
_, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=test", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import "context"
func (c *Container) Echo(ctx context.Context, msg string) (string, error) {
return c.WithExec([]string{"echo", msg}).Stdout(ctx)
}
`,
}).
With(daggerExec("mod", "sync")).
Sync(ctx)
require.Error(t, err)
require.NoError(t, c.Close())
require.Contains(t, logs.String(), "cannot define methods on objects from outside this module")
}
func TestModuleCustomTypes(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
import "strings"
type Test struct{}
func (m *Test) Repeater(msg string, times int) *Repeater {
return &Repeater{
Message: msg,
Times: times,
}
}
type Repeater struct {
Message string
Times int
}
func (t *Repeater) Render() string {
return strings.Repeat(t.Message, t.Times)
}
`,
},
{
sdk: "python",
source: `from dagger import field, function, object_type
@object_type |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | class Repeater:
message: str = field(default="")
times: int = field(default=0)
@function
def render(self) -> str:
return self.message * self.times
@function
def repeater(msg: str, times: int) -> Repeater:
return Repeater(message=msg, times=times)
`,
},
} {
tc := tc
t.Run(fmt.Sprintf("custom %s types", tc.sdk), func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=test", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(daggerQuery(`{test{repeater(msg:"echo!", times: 3){render}}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"test":{"repeater":{"render":"echo!echo!echo!"}}}`, out)
})
}
}
func TestModuleReturnTypeDetection(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
type testCase struct {
sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
type Foo struct {}
type X struct {
Message string ` + "`json:\"message\"`" + `
}
func (m *Foo) MyFunction() X {
return X{Message: "foo"}
}
`,
},
{
sdk: "python",
source: `from dagger import field, function, object_type |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | @object_type
class X:
message: str = field(default="")
@function
def my_function() -> X:
return X(message="foo")
`,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=foo", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(daggerQuery(`{foo{myFunction{message}}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"foo":{"myFunction":{"message":"foo"}}}`, out)
})
}
}
func TestModuleReturnObject(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
type Foo struct {}
type X struct {
Message string ` + "`json:\"message\"`" + `
When string ` + "`json:\"Timestamp\"`" + `
To string ` + "`json:\"recipient\"`" + `
From string
}
func (m *Foo) MyFunction() X {
return X{Message: "foo", When: "now", To: "user", From: "admin"}
}
`,
},
{
sdk: "python",
source: `from dagger import field, function, object_type
@object_type
class X:
message: str = field(default="")
when: str = field(default="", name="Timestamp")
to: str = field(default="", name="recipient") |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | from_: str = field(default="", name="from")
@object_type
class Foo:
@function
def my_function(self) -> X:
return X(message="foo", when="now", to="user", from_="admin")
`,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=foo", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(daggerQuery(`{foo{myFunction{message, recipient, from, timestamp}}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"foo":{"myFunction":{"message":"foo", "recipient":"user", "from":"admin", "timestamp":"now"}}}`, out)
})
}
}
func TestModuleReturnNestedObject(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
type Playground struct{}
type Foo struct {
MsgContainer Bar
}
type Bar struct {
Msg string
}
func (m *Playground) MyFunction() Foo {
return Foo{MsgContainer: Bar{Msg: "hello world"}}
}
`,
},
{
sdk: "python",
source: `from dagger import field, function, object_type
@object_type
class Bar:
msg: str = field()
@object_type
class Foo: |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | msg_container: Bar = field()
@object_type
class Playground:
@function
def my_function(self) -> Foo:
return Foo(msg_container=Bar(msg="hello world"))
`,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=playground", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(daggerQuery(`{playground{myFunction{msgContainer{msg}}}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"playground":{"myFunction":{"msgContainer":{"msg": "hello world"}}}}`, out)
})
}
}
func TestModuleReturnCompositeCore(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
type Playground struct{}
func (m *Playground) MySlice() []*Container {
return []*Container{dag.Container().From("alpine:latest").WithExec([]string{"echo", "hello world"})}
}
type Foo struct {
Con *Container
// verify fields can remain nil w/out error too
UnsetFile *File
}
func (m *Playground) MyStruct() *Foo {
return &Foo{Con: dag.Container().From("alpine:latest").WithExec([]string{"echo", "hello world"})}
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | `,
},
{
sdk: "python",
source: `import dagger
from dagger import dag, field, function, object_type
@object_type
class Foo:
con: dagger.Container = field()
unset_file: dagger.File | None = field(default=None)
@object_type
class Playground:
@function
def my_slice(self) -> list[dagger.Container]:
return [dag.container().from_("alpine:latest").with_exec(["echo", "hello world"])]
@function
def my_struct(self) -> Foo:
return Foo(con=dag.container().from_("alpine:latest").with_exec(["echo", "hello world"]))
`,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=playground", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
if tc.sdk == "go" { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(daggerQuery(`{playground{mySlice{stdout}}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"playground":{"mySlice":[{"stdout":"hello world\n"}]}}`, out)
out, err = modGen.With(daggerQuery(`{playground{myStruct{con{stdout}}}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"playground":{"myStruct":{"con":{"stdout":"hello world\n"}}}}`, out)
})
}
}
func TestModuleReturnComplexThing(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct {
sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
type Playground struct{}
type ScanResult struct {
Containers []*Container ` + "`json:\"targets\"`" + `
Report ScanReport
}
type ScanReport struct {
Contents string ` + "`json:\"contents\"`" + `
Authors []string ` + "`json:\"Authors\"`" + ` |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | }
func (m *Playground) Scan() ScanResult {
return ScanResult{
Containers: []*Container{
dag.Container().From("alpine:latest").WithExec([]string{"echo", "hello world"}),
},
Report: ScanReport{
Contents: "hello world",
Authors: []string{"foo", "bar"},
},
}
}
`,
},
{
sdk: "python",
source: `import dagger
from dagger import dag, field, function, object_type
@object_type
class ScanReport:
contents: str = field()
authors: list[str] = field()
@object_type
class ScanResult:
containers: list[dagger.Container] = field(name="targets")
report: ScanReport = field()
@object_type
class Playground:
@function
def scan(self) -> ScanResult: |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | return ScanResult(
containers=[
dag.container().from_("alpine:latest").with_exec(["echo", "hello world"]),
],
report=ScanReport(
contents="hello world",
authors=["foo", "bar"],
),
)
`,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=playground", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(daggerQuery(`{playground{scan{targets{stdout},report{contents,authors}}}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"playground":{"scan":{"targets":[{"stdout":"hello world\n"}],"report":{"contents":"hello world","authors":["foo","bar"]}}}}`, out)
})
}
}
func TestModulePythonReturnSelf(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=foo", "--sdk=python")).
WithNewFile("src/main.py", dagger.ContainerWithNewFileOpts{
Contents: `from typing import Self
from dagger import field, function, object_type
@object_type
class Foo:
message: str = field(default="")
@function
def bar(self) -> Self:
self.message = "foobar"
return self
`,
})
out, err := modGen.With(daggerQuery(`{foo{bar{message}}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"foo":{"bar":{"message":"foobar"}}}`, out)
}
func TestModuleGlobalVarDAG(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
import "context"
type Foo struct {}
var someDefault = dag.Container().From("alpine:latest")
func (m *Foo) Fn(ctx context.Context) (string, error) {
return someDefault.WithExec([]string{"echo", "foo"}).Stdout(ctx)
}
`,
},
{
sdk: "python",
source: `from dagger import dag, function, object_type
SOME_DEFAULT = dag.container().from_("alpine:latest")
@object_type
class Foo:
@function
async def fn(self) -> str:
return await SOME_DEFAULT.with_exec(["echo", "foo"]).stdout()
`,
}, |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | } {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=foo", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(daggerQuery(`{foo{fn}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"foo":{"fn":"foo\n"}}`, out)
})
}
}
func TestModuleIDableType(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct {
sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
type Foo struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | Data string
}
func (m *Foo) Set(data string) *Foo {
m.Data = data
return m
}
func (m *Foo) Get() string {
return m.Data
}
`,
},
{
sdk: "python",
source: `from typing import Self
from dagger import field, function, object_type
@object_type
class Foo:
data: str = ""
@function
def set(self, data: str) -> Self:
self.data = data
return self
@function
def get(self) -> str:
return self.data
`,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=foo", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(daggerQuery(`{foo{set(data: "abc"){get}}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"foo":{"set":{"get": "abc"}}}`, out)
out, err = modGen.With(daggerQuery(`{foo{set(data: "abc"){id}}}`)).Stdout(ctx)
require.NoError(t, err)
id := gjson.Get(out, "foo.set.id").String()
require.Contains(t, id, "moddata:")
out, err = modGen.With(daggerQuery(`{loadFooFromID(id: "%s"){get}}`, id)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"loadFooFromID":{"get": "abc"}}`, out)
})
}
}
func TestModuleArgOwnType(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
import "strings"
type Foo struct{}
type Message struct {
Content string
}
func (m *Foo) SayHello(name string) Message {
return Message{Content: "hello " + name}
}
func (m *Foo) Upper(msg Message) Message {
msg.Content = strings.ToUpper(msg.Content)
return msg
}
func (m *Foo) Uppers(msg []Message) []Message {
for i := range msg {
msg[i].Content = strings.ToUpper(msg[i].Content)
}
return msg
}`,
},
{
sdk: "python",
source: `from dagger import field, function, object_type |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | @object_type
class Message:
content: str = field()
@object_type
class Foo:
@function
def say_hello(self, name: str) -> Message:
return Message(content=f"hello {name}")
@function
def upper(self, msg: Message) -> Message:
msg.content = msg.content.upper()
return msg
@function
def uppers(self, msg: list[Message]) -> list[Message]:
for m in msg:
m.content = m.content.upper()
return msg
`,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=foo", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory(".")) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | }
out, err := modGen.With(daggerQuery(`{foo{sayHello(name: "world"){id}}}`)).Stdout(ctx)
require.NoError(t, err)
id := gjson.Get(out, "foo.sayHello.id").String()
require.Contains(t, id, "moddata:")
out, err = modGen.With(daggerQuery(`{foo{upper(msg:"%s"){content}}}`, id)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"foo":{"upper":{"content": "HELLO WORLD"}}}`, out)
out, err = modGen.With(daggerQuery(`{foo{uppers(msg:["%s", "%s"]){content}}}`, id, id)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"foo":{"uppers":[{"content": "HELLO WORLD"}, {"content": "HELLO WORLD"}]}}`, out)
})
}
}
func TestModuleConflictingSameNameDeps(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/dstr").
With(daggerExec("mod", "init", "--name=d", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type D struct{}
type Obj struct {
Foo string
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | func (m *D) Fn(foo string) Obj {
return Obj{Foo: foo}
}
`,
})
ctr = ctr.
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/dint").
With(daggerExec("mod", "init", "--name=d", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type D struct{}
type Obj struct {
Foo int
}
func (m *D) Fn(foo int) Obj {
return Obj{Foo: foo}
}
`,
})
ctr = ctr.
WithWorkdir("/work/c").
With(daggerExec("mod", "init", "--name=c", "--sdk=go", "--root=..")).
With(daggerExec("mod", "install", "../dstr")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import (
"context"
)
type C struct{} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | func (m *C) Fn(ctx context.Context, foo string) (string, error) {
return dag.D().Fn(foo).Foo(ctx)
}
`,
})
ctr = ctr.
WithWorkdir("/work/b").
With(daggerExec("mod", "init", "--name=b", "--sdk=go", "--root=..")).
With(daggerExec("mod", "install", "../dint")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import (
"context"
)
type B struct{}
func (m *B) Fn(ctx context.Context, foo int) (int, error) {
return dag.D().Fn(foo).Foo(ctx)
}
`,
})
ctr = ctr.
WithWorkdir("/work/a").
With(daggerExec("mod", "init", "--name=a", "--sdk=go", "--root=..")).
With(daggerExec("mod", "install", "../b")).
With(daggerExec("mod", "install", "../c")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import (
"context"
"strconv" |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | )
type A struct{}
func (m *A) Fn(ctx context.Context) (string, error) {
fooStr, err := dag.C().Fn(ctx, "foo")
if err != nil {
return "", err
}
fooInt, err := dag.B().Fn(ctx, 123)
if err != nil {
return "", err
}
return fooStr + strconv.Itoa(fooInt), nil
}
`,
})
out, err := ctr.With(daggerQuery(`{a{fn}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"a":{"fn": "foo123"}}`, out)
types := currentSchema(ctx, t, ctr).Types
require.NotNil(t, types.Get("A"))
require.Nil(t, types.Get("B"))
require.Nil(t, types.Get("C"))
require.Nil(t, types.Get("D"))
}
func TestModuleSelfAPICall(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
out, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=test", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import (
"context"
"github.com/Khan/genqlient/graphql"
)
type Test struct{}
func (m *Test) FnA(ctx context.Context) (string, error) {
resp := &graphql.Response{}
err := dag.c.MakeRequest(ctx, &graphql.Request{
Query: "{test{fnB}}",
}, resp)
if err != nil {
return "", err
}
return resp.Data.(map[string]any)["test"].(map[string]any)["fnB"].(string), nil
}
func (m *Test) FnB() string {
return "hi from b"
}
`,
}).
With(daggerQuery(`{test{fnA}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"test":{"fnA": "hi from b"}}`, out)
}
func TestModuleGoWithOtherModuleTypes(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/dep").
With(daggerExec("mod", "init", "--name=dep", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Dep struct{}
type Obj struct {
Foo string
}
func (m *Dep) Fn() Obj {
return Obj{Foo: "foo"}
}
`,
}).
WithWorkdir("/work/test").
With(daggerExec("mod", "init", "--name=test", "--sdk=go", "--root=..")).
With(daggerExec("mod", "install", "../dep"))
t.Run("return as other module object", func(t *testing.T) {
t.Parallel()
t.Run("direct", func(t *testing.T) {
t.Parallel()
_, err := ctr.
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Test struct{}
func (m *Test) Fn() (*DepObj, error) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | return nil, nil
}
`,
}).
With(daggerFunctions()).
Stdout(ctx)
require.Error(t, err)
require.ErrorContains(t, err, fmt.Sprintf(
"object %q function %q cannot return external type from dependency module %q",
"Test", "Fn", "dep",
))
})
t.Run("list", func(t *testing.T) {
t.Parallel()
_, err := ctr.
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Test struct{}
func (m *Test) Fn() ([]*DepObj, error) {
return nil, nil
}
`,
}).
With(daggerFunctions()).
Stdout(ctx)
require.Error(t, err)
require.ErrorContains(t, err, fmt.Sprintf(
"object %q function %q cannot return external type from dependency module %q",
"Test", "Fn", "dep",
)) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | })
})
t.Run("arg as other module object", func(t *testing.T) {
t.Parallel()
t.Run("direct", func(t *testing.T) {
t.Parallel()
_, err := ctr.WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Test struct{}
func (m *Test) Fn(obj *DepObj) error {
return nil
}
`,
}).
With(daggerFunctions()).
Stdout(ctx)
require.Error(t, err)
require.ErrorContains(t, err, fmt.Sprintf(
"object %q function %q arg %q cannot reference external type from dependency module %q",
"Test", "Fn", "obj", "dep",
))
})
t.Run("list", func(t *testing.T) {
t.Parallel()
_, err := ctr.WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Test struct{}
func (m *Test) Fn(obj []*DepObj) error {
return nil
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | `,
}).
With(daggerFunctions()).
Stdout(ctx)
require.Error(t, err)
require.ErrorContains(t, err, fmt.Sprintf(
"object %q function %q arg %q cannot reference external type from dependency module %q",
"Test", "Fn", "obj", "dep",
))
})
})
t.Run("field as other module object", func(t *testing.T) {
t.Parallel()
t.Run("direct", func(t *testing.T) {
t.Parallel()
_, err := ctr.
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Test struct{}
type Obj struct {
Foo *DepObj
}
func (m *Test) Fn() (*Obj, error) {
return nil, nil
}
`,
}).
With(daggerFunctions()).
Stdout(ctx)
require.Error(t, err) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.ErrorContains(t, err, fmt.Sprintf(
"object %q field %q cannot reference external type from dependency module %q",
"Obj", "Foo", "dep",
))
})
t.Run("list", func(t *testing.T) {
t.Parallel()
_, err := ctr.
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Test struct{}
type Obj struct {
Foo []*DepObj
}
func (m *Test) Fn() (*Obj, error) {
return nil, nil
}
`,
}).
With(daggerFunctions()).
Stdout(ctx)
require.Error(t, err)
require.ErrorContains(t, err, fmt.Sprintf(
"object %q field %q cannot reference external type from dependency module %q",
"Obj", "Foo", "dep",
))
})
})
}
func TestModulePythonWithOtherModuleTypes(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/dep").
With(daggerExec("mod", "init", "--name=dep", "--sdk=python")).
WithNewFile("src/main.py", dagger.ContainerWithNewFileOpts{
Contents: `from dagger import field, function, object_type
@object_type
class Foo:
...
@object_type
class Obj:
foo: str = field()
@object_type
class Dep:
@function
def fn(self) -> Obj:
return Obj(foo="foo")
`,
}).
WithWorkdir("/work/test").
With(daggerExec("mod", "init", "--name=test", "--sdk=python", "--root=..")).
With(daggerExec("mod", "install", "../dep"))
t.Run("return as other module object", func(t *testing.T) {
t.Parallel()
t.Run("direct", func(t *testing.T) {
t.Parallel()
_, err := ctr.
WithNewFile("src/main.py", dagger.ContainerWithNewFileOpts{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | Contents: `import dagger
@dagger.object_type
class Test:
@dagger.function
def fn(self) -> dagger.DepObj:
...
`,
}).
With(daggerFunctions()).
Stdout(ctx)
require.Error(t, err)
require.ErrorContains(t, err, fmt.Sprintf(
"object %q function %q cannot return external type from dependency module %q",
"Test", "fn", "dep",
))
})
t.Run("list", func(t *testing.T) {
t.Parallel()
_, err := ctr.
WithNewFile("src/main.py", dagger.ContainerWithNewFileOpts{
Contents: `import dagger
@dagger.object_type
class Test:
@dagger.function
def fn(self) -> list[dagger.DepObj]:
...
`,
}).
With(daggerFunctions()).
Stdout(ctx) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.Error(t, err)
require.ErrorContains(t, err, fmt.Sprintf(
"object %q function %q cannot return external type from dependency module %q",
"Test", "fn", "dep",
))
})
})
t.Run("arg as other module object", func(t *testing.T) {
t.Parallel()
t.Run("direct", func(t *testing.T) {
t.Parallel()
_, err := ctr.WithNewFile("src/main.py", dagger.ContainerWithNewFileOpts{
Contents: `import dagger
@dagger.object_type
class Test:
@dagger.function
def fn(self, obj: dagger.DepObj):
...
`,
}).
With(daggerFunctions()).
Stdout(ctx)
require.Error(t, err)
require.ErrorContains(t, err, fmt.Sprintf(
"object %q function %q arg %q cannot reference external type from dependency module %q",
"Test", "fn", "obj", "dep",
))
})
t.Run("list", func(t *testing.T) {
t.Parallel() |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | _, err := ctr.WithNewFile("src/main.py", dagger.ContainerWithNewFileOpts{
Contents: `import dagger
@dagger.object_type
class Test:
@dagger.function
def fn(self, obj: list[dagger.DepObj]):
...
`,
}).
With(daggerFunctions()).
Stdout(ctx)
require.Error(t, err)
require.ErrorContains(t, err, fmt.Sprintf(
"object %q function %q arg %q cannot reference external type from dependency module %q",
"Test", "fn", "obj", "dep",
))
})
})
t.Run("field as other module object", func(t *testing.T) {
t.Parallel()
t.Run("direct", func(t *testing.T) {
t.Parallel()
_, err := ctr.
WithNewFile("src/main.py", dagger.ContainerWithNewFileOpts{
Contents: `import dagger
@dagger.object_type
class Obj:
foo: dagger.DepObj = dagger.field()
@dagger.object_type
class Test: |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | @dagger.function
def fn(self) -> Obj:
...
`,
}).
With(daggerFunctions()).
Stdout(ctx)
require.Error(t, err)
require.ErrorContains(t, err, fmt.Sprintf(
"object %q field %q cannot reference external type from dependency module %q",
"Obj", "foo", "dep",
))
})
t.Run("list", func(t *testing.T) {
t.Parallel()
_, err := ctr.
WithNewFile("src/main.py", dagger.ContainerWithNewFileOpts{
Contents: `import dagger
@dagger.object_type
class Obj:
foo: list[dagger.DepObj] = dagger.field()
@dagger.object_type
class Test:
@dagger.function
def fn(self) -> list[Obj]:
...
`,
}).
With(daggerFunctions()).
Stdout(ctx) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.Error(t, err)
require.ErrorContains(t, err, fmt.Sprintf(
"object %q field %q cannot reference external type from dependency module %q",
"Obj", "foo", "dep",
))
})
})
}
var useInner = `package main
type Dep struct{}
func (m *Dep) Hello() string {
return "hello"
}
`
var useGoOuter = `package main
import "context"
type Use struct{}
func (m *Use) UseHello(ctx context.Context) (string, error) {
return dag.Dep().Hello(ctx)
}
`
var usePythonOuter = `from dagger import dag, function
@function
def use_hello() -> str:
return dag.dep().hello()
`
func TestModuleUseLocal(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: useGoOuter,
},
{
sdk: "python",
source: usePythonOuter,
}, |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | } {
tc := tc
t.Run(fmt.Sprintf("%s uses go", tc.sdk), func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/dep").
With(daggerExec("mod", "init", "--name=dep", "--sdk=go")).
With(sdkSource("go", useInner)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=use", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source)).
With(daggerExec("mod", "install", "./dep"))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(daggerQuery(`{use{useHello}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"use":{"useHello":"hello"}}`, out)
_, err = modGen.With(daggerQuery(`{dep{hello}}`)).Stdout(ctx)
require.Error(t, err)
require.ErrorContains(t, err, `Cannot query field "dep" on type "Query".`)
})
}
}
func TestModuleCodegenOnDepChange(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
changed string
expected string
}
for _, tc := range []testCase{
{
sdk: "go",
source: useGoOuter,
expected: "Hellov2",
changed: strings.ReplaceAll(useGoOuter, `Hello(ctx)`, `Hellov2(ctx)`),
},
{
sdk: "python",
source: usePythonOuter,
expected: "hellov2",
changed: strings.ReplaceAll(usePythonOuter, `.hello()`, `.hellov2()`),
},
} {
tc := tc
t.Run(fmt.Sprintf("%s uses go", tc.sdk), func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/dep").
With(daggerExec("mod", "init", "--name=dep", "--sdk=go")).
With(sdkSource("go", useInner)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=use", "--sdk="+tc.sdk)). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | With(sdkSource(tc.sdk, tc.source)).
With(daggerExec("mod", "install", "./dep"))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(daggerQuery(`{use{useHello}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"use":{"useHello":"hello"}}`, out)
newInner := strings.ReplaceAll(useInner, `Hello()`, `Hellov2()`)
modGen = modGen.
WithWorkdir("/work/dep").
With(sdkSource("go", newInner)).
WithWorkdir("/work").
With(daggerExec("mod", "sync"))
codegenContents, err := modGen.File(sdkCodegenFile(t, tc.sdk)).Contents(ctx)
require.NoError(t, err)
require.Contains(t, codegenContents, tc.expected)
modGen = modGen.With(sdkSource(tc.sdk, tc.changed))
out, err = modGen.With(daggerQuery(`{use{useHello}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"use":{"useHello":"hello"}}`, out)
})
}
}
func TestModuleSyncDeps(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: useGoOuter,
},
{
sdk: "python",
source: usePythonOuter,
},
} {
tc := tc
t.Run(fmt.Sprintf("%s uses go", tc.sdk), func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/dep").
With(daggerExec("mod", "init", "--name=dep", "--sdk=go")).
With(sdkSource("go", useInner)). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=use", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source)).
With(daggerExec("mod", "install", "./dep"))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
modGen = modGen.With(daggerQuery(`{use{useHello}}`))
out, err := modGen.Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"use":{"useHello":"hello"}}`, out)
newInner := strings.ReplaceAll(useInner, `"hello"`, `"goodbye"`)
modGen = modGen.
WithWorkdir("/work/dep").
With(sdkSource("go", newInner)).
WithWorkdir("/work").
With(daggerExec("mod", "sync"))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err = modGen.With(daggerQuery(`{use{useHello}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"use":{"useHello":"goodbye"}}`, out)
})
}
}
func TestModuleUseLocalMulti(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
import "context"
import "fmt"
type Use struct {}
func (m *Use) Names(ctx context.Context) ([]string, error) {
fooName, err := dag.Foo().Name(ctx)
if err != nil {
return nil, fmt.Errorf("foo.name: %w", err)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | barName, err := dag.Bar().Name(ctx)
if err != nil {
return nil, fmt.Errorf("bar.name: %w", err)
}
return []string{fooName, barName}, nil
}
`,
},
{
sdk: "python",
source: `from dagger import dag, function
@function
async def names() -> list[str]:
return [
await dag.foo().name(),
await dag.bar().name(),
]
`,
},
} {
tc := tc
t.Run(fmt.Sprintf("%s uses go", tc.sdk), func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/foo").
WithNewFile("/work/foo/main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Foo struct {}
func (m *Foo) Name() string { return "foo" } |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | `,
}).
With(daggerExec("mod", "init", "--name=foo", "--sdk=go")).
WithWorkdir("/work/bar").
WithNewFile("/work/bar/main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Bar struct {}
func (m *Bar) Name() string { return "bar" }
`,
}).
With(daggerExec("mod", "init", "--name=bar", "--sdk=go")).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=use", "--sdk="+tc.sdk)).
With(daggerExec("mod", "install", "./foo")).
With(daggerExec("mod", "install", "./bar")).
With(sdkSource(tc.sdk, tc.source)).
WithEnvVariable("BUST", identity.NewID())
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
out, err := modGen.With(daggerQuery(`{use{names}}`)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"use":{"names":["foo", "bar"]}}`, out)
})
}
}
func TestModuleConstructor(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
type testCase struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk string
source string
}
t.Run("basic", func(t *testing.T) {
t.Parallel()
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
import (
"context"
)
func New(
ctx context.Context,
foo string,
bar Optional[int],
baz []string,
dir *Directory,
) *Test {
return &Test{
Foo: foo,
Bar: bar.GetOr(42),
Baz: baz,
Dir: dir,
}
}
type Test struct {
Foo string
Bar int |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | Baz []string
Dir *Directory
NeverSetDir *Directory
}
func (m *Test) GimmeFoo() string {
return m.Foo
}
func (m *Test) GimmeBar() int {
return m.Bar
}
func (m *Test) GimmeBaz() []string {
return m.Baz
}
func (m *Test) GimmeDirEnts(ctx context.Context) ([]string, error) {
return m.Dir.Entries(ctx)
}
`,
},
{
sdk: "python",
source: `import dagger
from dagger import field, function, object_type
@object_type
class Test:
foo: str = field()
dir: dagger.Directory = field()
bar: int = field(default=42)
baz: list[str] = field(default=list)
never_set_dir: dagger.Directory | None = field(default=None)
@function |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | def gimme_foo(self) -> str:
return self.foo
@function
def gimme_bar(self) -> int:
return self.bar
@function
def gimme_baz(self) -> list[str]:
return self.baz
@function
async def gimme_dir_ents(self) -> list[str]:
return await self.dir.entries()
`,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/test").
With(daggerExec("mod", "init", "--name=test", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
out, err := ctr.With(daggerCall("--foo=abc", "--baz=x,y,z", "--dir=.", "foo")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "abc")
out, err = ctr.With(daggerCall("--foo=abc", "--baz=x,y,z", "--dir=.", "gimme-foo")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "abc")
out, err = ctr.With(daggerCall("--foo=abc", "--baz=x,y,z", "--dir=.", "bar")).Stdout(ctx)
require.NoError(t, err) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | require.Equal(t, strings.TrimSpace(out), "42")
out, err = ctr.With(daggerCall("--foo=abc", "--baz=x,y,z", "--dir=.", "gimme-bar")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "42")
out, err = ctr.With(daggerCall("--foo=abc", "--bar=123", "--baz=x,y,z", "--dir=.", "bar")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "123")
out, err = ctr.With(daggerCall("--foo=abc", "--bar=123", "--baz=x,y,z", "--dir=.", "gimme-bar")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "123")
out, err = ctr.With(daggerCall("--foo=abc", "--bar=123", "--baz=x,y,z", "--dir=.", "baz")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "x\ny\nz")
out, err = ctr.With(daggerCall("--foo=abc", "--bar=123", "--baz=x,y,z", "--dir=.", "gimme-baz")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "x\ny\nz")
out, err = ctr.With(daggerCall("--foo=abc", "--bar=123", "--baz=x,y,z", "--dir=.", "gimme-dir-ents")).Stdout(ctx)
require.NoError(t, err)
require.Contains(t, strings.TrimSpace(out), "dagger.json")
})
}
})
t.Run("fields only", func(t *testing.T) {
t.Parallel()
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
import (
"context" |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | )
func New(ctx context.Context) (Test, error) {
v, err := dag.Container().From("alpine:3.18.4").File("/etc/alpine-release").Contents(ctx)
if err != nil {
return Test{}, err
}
return Test{
AlpineVersion: v,
}, nil
}
type Test struct {
AlpineVersion string
}
`,
},
{
sdk: "python",
source: `from dagger import dag, field, function, object_type
@object_type
class Test:
alpine_version: str = field()
@classmethod
async def create(cls) -> "Test":
return cls(alpine_version=await (
dag.container()
.from_("alpine:3.18.4")
.file("/etc/alpine-release")
.contents()
))
`, |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | },
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/test").
With(daggerExec("mod", "init", "--name=test", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
out, err := ctr.With(daggerCall("alpine-version")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "3.18.4")
})
}
})
t.Run("return error", func(t *testing.T) {
t.Parallel()
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
import (
"fmt"
)
func New() (*Test, error) {
return nil, fmt.Errorf("too bad")
}
type Test struct {
Foo string |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | }
`,
},
{
sdk: "python",
source: `from dagger import object_type, field
@object_type
class Test:
foo: str = field()
def __init__(self):
raise ValueError("too bad")
`,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
var logs safeBuffer
c, ctx := connect(t, dagger.WithLogOutput(&logs))
ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/test").
With(daggerExec("mod", "init", "--name=test", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
_, err := ctr.With(daggerCall("foo")).Stdout(ctx)
require.Error(t, err)
require.Contains(t, logs.String(), "too bad")
})
}
}) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Run("python: with default factory", func(t *testing.T) {
t.Parallel()
content := identity.NewID()
ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/test").
With(daggerExec("mod", "init", "--name=test", "--sdk=python")).
With(sdkSource("python", fmt.Sprintf(`import dagger
from dagger import dag, object_type, field
@object_type
class Test:
foo: dagger.File = field(default=lambda: (
dag.directory()
.with_new_file("foo.txt", contents="%s")
.file("foo.txt")
))
bar: list[str] = field(default=list)
`, content),
))
out, err := ctr.With(daggerCall("foo")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), content)
out, err = ctr.With(daggerCall("--foo=dagger.json", "foo")).Stdout(ctx)
require.NoError(t, err)
require.Contains(t, out, `"sdk": "python"`)
_, err = ctr.With(daggerCall("bar")).Sync(ctx)
require.NoError(t, err)
})
}
func TestModuleWrapping(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
type testCase struct {
sdk string
source string
}
for _, tc := range []testCase{
{
sdk: "go",
source: `package main
type Wrapper struct{}
func (m *Wrapper) Container() *WrappedContainer {
return &WrappedContainer{
dag.Container().From("alpine"),
}
}
type WrappedContainer struct {
Unwrap *Container` + "`" + `json:"unwrap"` + "`" + `
}
func (c *WrappedContainer) Echo(msg string) *WrappedContainer {
return &WrappedContainer{
c.Unwrap.WithExec([]string{"echo", "-n", msg}),
}
}
`,
},
{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | sdk: "python",
source: `from typing import Self
import dagger
from dagger import dag, field, function, object_type
@object_type
class WrappedContainer:
unwrap: dagger.Container = field()
@function
def echo(self, msg: str) -> Self:
return WrappedContainer(unwrap=self.unwrap.with_exec(["echo", "-n", msg]))
@object_type
class Wrapper:
@function
def container(self) -> WrappedContainer:
return WrappedContainer(unwrap=dag.container().from_("alpine"))
`,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=wrapper", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source))
if tc.sdk == "go" {
logGen(ctx, t, modGen.Directory("."))
}
id := identity.NewID() |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | out, err := modGen.With(daggerQuery(
fmt.Sprintf(`{wrapper{container{echo(msg:%q){unwrap{stdout}}}}}`, id),
)).Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t,
fmt.Sprintf(`{"wrapper":{"container":{"echo":{"unwrap":{"stdout":%q}}}}}`, id),
out)
})
}
}
func TestModuleConfigAPI(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
moduleDir := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/subdir").
With(daggerExec("mod", "init", "--name=test", "--sdk=go", "--root=..")).
Directory("/work")
cfg := c.ModuleConfig(moduleDir, dagger.ModuleConfigOpts{Subpath: "subdir"})
name, err := cfg.Name(ctx)
require.NoError(t, err)
require.Equal(t, "test", name)
sdk, err := cfg.SDK(ctx)
require.NoError(t, err)
require.Equal(t, "go", sdk)
root, err := cfg.Root(ctx)
require.NoError(t, err)
require.Equal(t, "..", root)
}
func TestModuleTypescriptInit(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Run("from scratch", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=bare", "--sdk=typescript"))
out, err := modGen.
With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out)
})
t.Run("with different root", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/child").
With(daggerExec("mod", "init", "--name=bare", "--sdk=typescript", "--root=.."))
out, err := modGen.
With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out)
})
t.Run("camel-cases Dagger module name", func(t *testing.T) {
t.Parallel() |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=My-Module", "--sdk=go"))
out, err := modGen.
With(daggerQuery(`{myModule{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"myModule":{"containerEcho":{"stdout":"hello\n"}}}`, out)
})
}
func TestModuleLotsOfFunctions(t *testing.T) {
t.Parallel()
const funcCount = 100
t.Run("go sdk", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
mainSrc := `
package main
type PotatoSack struct {}
`
for i := 0; i < funcCount; i++ {
mainSrc += fmt.Sprintf(`
func (m *PotatoSack) Potato%d() string {
return "potato #%d"
}
`, i, i)
}
modGen := c.Container().From(golangImage). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
Contents: mainSrc,
}).
With(daggerExec("mod", "init", "--name=potatoSack", "--sdk=go"))
logGen(ctx, t, modGen.Directory("."))
var eg errgroup.Group
for i := 0; i < funcCount; i++ {
i := i
if i%10 != 0 {
continue
}
eg.Go(func() error {
_, err := modGen.
With(daggerCall(fmt.Sprintf("potato%d", i))).
Sync(ctx)
return err
})
}
require.NoError(t, eg.Wait())
})
t.Run("python sdk", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
mainSrc := `from dagger import function
`
for i := 0; i < funcCount; i++ {
mainSrc += fmt.Sprintf(` |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | @function
def potato_%d() -> str:
return "potato #%d"
`, i, i)
}
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("./src/main.py", dagger.ContainerWithNewFileOpts{
Contents: mainSrc,
}).
With(daggerExec("mod", "init", "--name=potatoSack", "--sdk=python"))
var eg errgroup.Group
for i := 0; i < funcCount; i++ {
i := i
if i%10 != 0 {
continue
}
eg.Go(func() error {
_, err := modGen.
With(daggerCall(fmt.Sprintf("potato%d", i))).
Sync(ctx)
return err
})
}
require.NoError(t, eg.Wait())
})
}
func TestModuleLotsOfDeps(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work")
modCount := 0
getModMainSrc := func(name string, depNames []string) string {
t.Helper()
mainSrc := fmt.Sprintf(`package main
import "context"
type %s struct {}
func (m *%s) Fn(ctx context.Context) (string, error) {
s := "%s"
var depS string
_ = depS
var err error
_ = err
`, strcase.ToCamel(name), strcase.ToCamel(name), name)
for _, depName := range depNames {
mainSrc += fmt.Sprintf(`
depS, err = dag.%s().Fn(ctx)
if err != nil {
return "", err |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | }
s += depS
`, strcase.ToCamel(depName))
}
mainSrc += "return s, nil\n}\n"
fmted, err := format.Source([]byte(mainSrc))
require.NoError(t, err)
return string(fmted)
}
getModDaggerConfig := func(name string, depNames []string) string {
t.Helper()
var depVals []string
for _, depName := range depNames {
depVals = append(depVals, "../"+depName)
}
cfg := modules.Config{
Name: name,
Root: "..",
SDK: "go",
Dependencies: depVals,
}
bs, err := json.Marshal(cfg)
require.NoError(t, err)
return string(bs)
}
addModulesWithDeps := func(newMods int, depNames []string) []string {
t.Helper()
var newModNames []string |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | for i := 0; i < newMods; i++ {
name := fmt.Sprintf("mod%d", modCount)
modCount++
newModNames = append(newModNames, name)
modGen = modGen.
WithWorkdir("/work/"+name).
WithNewFile("./main.go", dagger.ContainerWithNewFileOpts{
Contents: getModMainSrc(name, depNames),
}).
WithNewFile("./dagger.json", dagger.ContainerWithNewFileOpts{
Contents: getModDaggerConfig(name, depNames),
})
}
return newModNames
}
curDeps := addModulesWithDeps(1, nil)
for i := 0; i < 6; i++ {
curDeps = addModulesWithDeps(len(curDeps)+1, curDeps)
}
addModulesWithDeps(1, curDeps)
_, err := modGen.With(daggerCall("fn")).Stdout(ctx)
require.NoError(t, err)
}
func TestModuleNamespacing(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
moduleSrcPath, err := filepath.Abs("./testdata/modules/go/namespacing")
require.NoError(t, err)
ctr := c.Container().From(alpineImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithMountedDirectory("/work", c.Host().Directory(moduleSrcPath)).
WithWorkdir("/work")
out, err := ctr.
With(daggerQuery(`{test{fn(s:"yo")}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"test":{"fn":["*main.Sub1Obj made 1:yo", "*main.Sub2Obj made 2:yo"]}}`, out)
}
func TestModuleRoots(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
moduleSrcPath, err := filepath.Abs("./testdata/modules/go/roots")
require.NoError(t, err)
entries, err := os.ReadDir(moduleSrcPath)
require.NoError(t, err)
ctr := c.Container().From(alpineImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithMountedDirectory("/work", c.Host().Directory(moduleSrcPath))
for _, entry := range entries {
entry := entry
t.Run(entry.Name(), func(t *testing.T) {
t.Parallel()
ctr := ctr.WithWorkdir("/work/" + entry.Name())
out, err := ctr.
With(daggerQuery(fmt.Sprintf(`{%s{hello}}`, strcase.ToLowerCamel(entry.Name())))).
Stdout(ctx)
if strings.HasPrefix(entry.Name(), "good-") {
require.NoError(t, err)
require.JSONEq(t, fmt.Sprintf(`{"%s":{"hello": "hello"}}`, strcase.ToLowerCamel(entry.Name())), out)
} else if strings.HasPrefix(entry.Name(), "bad-") {
require.Error(t, err)
require.Regexp(t, "is not under( module)? root", err.Error())
}
})
}
}
func TestModuleDaggerCall(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
t.Run("service args", func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=test", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import (
"context"
)
type Test struct {}
func (m *Test) Fn(ctx context.Context, svc *Service) (string, error) {
return dag.Container().From("alpine:3.18").WithExec([]string{"apk", "add", "curl"}).
WithServiceBinding("daserver", svc).
WithExec([]string{"curl", "http://daserver:8000"}).
Stdout(ctx)
}
`,
}) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | logGen(ctx, t, modGen.Directory("."))
httpServer, _ := httpService(ctx, t, c, "im up")
endpoint, err := httpServer.Endpoint(ctx)
require.NoError(t, err)
out, err := modGen.
WithServiceBinding("testserver", httpServer).
With(daggerCall("fn", "--svc", "tcp://"+endpoint)).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "im up")
})
t.Run("list args", func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("foo.txt", dagger.ContainerWithNewFileOpts{
Contents: "bar",
}).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import (
"context"
"strings"
)
type Minimal struct {}
func (m *Minimal) Hello(msgs []string) string {
return strings.Join(msgs, "+")
}
func (m *Minimal) Reads(ctx context.Context, files []File) (string, error) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | var contents []string
for _, f := range files {
content, err := f.Contents(ctx)
if err != nil {
return "", err
}
contents = append(contents, content)
}
return strings.Join(contents, "+"), nil
}
`,
})
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.With(daggerCall("hello", "--msgs", "yo", "--msgs", "my", "--msgs", "friend")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "yo+my+friend")
out, err = modGen.With(daggerCall("reads", "--files=foo.txt", "--files=foo.txt")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "bar+bar")
})
t.Run("return list objects", func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Minimal struct {}
type Foo struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | Bar int ` + "`" + `json:"bar"` + "`" + `
}
func (m *Minimal) Fn() []*Foo {
var foos []*Foo
for i := 0; i < 3; i++ {
foos = append(foos, &Foo{Bar: i})
}
return foos
}
`,
})
logGen(ctx, t, modGen.Directory("."))
out, err := modGen.With(daggerCall("fn", "bar")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "0\n1\n2")
})
t.Run("directory arg inputs", func(t *testing.T) {
t.Parallel()
t.Run("local dir", func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=test", "--sdk=go")).
WithNewFile("/dir/subdir/foo.txt", dagger.ContainerWithNewFileOpts{
Contents: "foo",
}).
WithNewFile("/dir/subdir/bar.txt", dagger.ContainerWithNewFileOpts{
Contents: "bar",
}). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Test struct {}
func (m *Test) Fn(dir *Directory) *Directory {
return dir
}
`,
})
out, err := modGen.With(daggerCall("fn", "--dir", "/dir/subdir")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "bar.txt\nfoo.txt")
out, err = modGen.With(daggerCall("fn", "--dir", "file:///dir/subdir")).Stdout(ctx)
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(out), "bar.txt\nfoo.txt")
})
t.Run("git dir", func(t *testing.T) {
t.Parallel()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=test", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
type Test struct {}
func (m *Test) Fn(dir *Directory, subpath Optional[string]) *Directory {
return dir.Directory(subpath.GetOr("."))
}
`,
})
for _, tc := range []struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | baseURL string
subpath string
}{
{
baseURL: "https://github.com/dagger/dagger",
},
{
baseURL: "https://github.com/dagger/dagger",
subpath: ".changes", |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | },
{
baseURL: "https://github.com/dagger/dagger.git",
},
{
baseURL: "https://github.com/dagger/dagger.git",
subpath: ".changes",
},
} {
tc := tc
t.Run(fmt.Sprintf("%s:%s", tc.baseURL, tc.subpath), func(t *testing.T) {
t.Parallel()
url := tc.baseURL + "#v0.9.1"
if tc.subpath != "" {
url += ":" + tc.subpath
}
args := []string{"fn", "--dir", url}
if tc.subpath == "" {
args = append(args, "--subpath", ".changes")
}
out, err := modGen.With(daggerCall(args...)).Stdout(ctx)
require.NoError(t, err)
require.Contains(t, out, "v0.9.1.md")
require.NotContains(t, out, "v0.9.2.md")
})
}
})
})
}
func TestModuleLoops(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
_, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/depA").
With(daggerExec("mod", "init", "--name=depA", "--sdk=go", "--root=..")).
WithWorkdir("/work/depB").
With(daggerExec("mod", "init", "--name=depB", "--sdk=go", "--root=..")).
With(daggerExec("mod", "install", "../depA")).
WithWorkdir("/work/depC").
With(daggerExec("mod", "init", "--name=depC", "--sdk=go", "--root=..")).
With(daggerExec("mod", "install", "../depB")).
WithWorkdir("/work/depA").
With(daggerExec("mod", "install", "../depC")).
Sync(ctx)
require.ErrorContains(t, err, "module depA has a circular dependency")
}
var badIDArgGoSrc string
var badIDArgPySrc string
var badIDFieldGoSrc string
var badIDFnGoSrc string
var badIDFnPySrc string
func TestModuleReservedWords(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
t.Run("id", func(t *testing.T) {
t.Parallel()
t.Run("arg", func(t *testing.T) {
t.Parallel()
t.Run("go", func(t *testing.T) {
t.Parallel()
_, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=test", "--sdk=go")).
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
Contents: badIDArgGoSrc,
}).
With(daggerQuery(`{test{fn(id:"no")}}`)).
Sync(ctx)
require.ErrorContains(t, err, "cannot define argument with reserved name \"id\"")
})
t.Run("python", func(t *testing.T) {
t.Parallel()
_, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=test", "--sdk=python")).
WithNewFile("/work/src/main.py", dagger.ContainerWithNewFileOpts{
Contents: badIDArgPySrc,
}). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | With(daggerQuery(`{test{fn(id:"no")}}`)).
Sync(ctx)
require.ErrorContains(t, err, "cannot define argument with reserved name \"id\"")
})
})
t.Run("field", func(t *testing.T) {
t.Parallel()
t.Run("go", func(t *testing.T) {
t.Parallel()
_, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=test", "--sdk=go")).
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
Contents: badIDFieldGoSrc,
}).
With(daggerQuery(`{test{fn{id}}}`)).
Sync(ctx)
require.ErrorContains(t, err, "cannot define field with reserved name \"id\"")
})
})
t.Run("fn", func(t *testing.T) {
t.Parallel()
t.Run("go", func(t *testing.T) {
t.Parallel()
_, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=test", "--sdk=go")).
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | Contents: badIDFnGoSrc,
}).
With(daggerQuery(`{test{id}}`)).
Sync(ctx)
require.ErrorContains(t, err, "cannot define function with reserved name \"id\"")
})
t.Run("python", func(t *testing.T) {
t.Parallel()
_, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("mod", "init", "--name=test", "--sdk=python")).
WithNewFile("/work/src/main.py", dagger.ContainerWithNewFileOpts{
Contents: badIDFnPySrc,
}).
With(daggerQuery(`{test{fn(id:"no")}}`)).
Sync(ctx)
require.ErrorContains(t, err, "cannot define function with reserved name \"id\"")
})
})
})
}
func daggerExec(args ...string) dagger.WithContainerFunc {
return func(c *dagger.Container) *dagger.Container {
return c.WithExec(append([]string{"dagger", "--debug"}, args...), dagger.ContainerWithExecOpts{
ExperimentalPrivilegedNesting: true,
})
}
}
func daggerQuery(query string, args ...any) dagger.WithContainerFunc { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | query = fmt.Sprintf(query, args...)
return func(c *dagger.Container) *dagger.Container {
return c.WithExec([]string{"dagger", "--debug", "query"}, dagger.ContainerWithExecOpts{
Stdin: query,
ExperimentalPrivilegedNesting: true,
})
}
}
func daggerCall(args ...string) dagger.WithContainerFunc {
return func(c *dagger.Container) *dagger.Container {
return c.WithExec(append([]string{"dagger", "--debug", "call"}, args...), dagger.ContainerWithExecOpts{
ExperimentalPrivilegedNesting: true,
})
}
}
func daggerFunctions(args ...string) dagger.WithContainerFunc {
return func(c *dagger.Container) *dagger.Container {
return c.WithExec(append([]string{"dagger", "--debug", "functions"}, args...), dagger.ContainerWithExecOpts{
ExperimentalPrivilegedNesting: true,
})
}
}
func hostDaggerCommand(ctx context.Context, t testing.TB, workdir string, args ...string) *exec.Cmd {
t.Helper()
cmd := exec.CommandContext(ctx, daggerCliPath(t), args...)
cmd.Dir = workdir
return cmd
}
func hostDaggerExec(ctx context.Context, t testing.TB, workdir string, args ...string) ([]byte, error) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Helper()
cmd := hostDaggerCommand(ctx, t, workdir, args...)
output, err := cmd.CombinedOutput()
if err != nil {
err = fmt.Errorf("%s: %w", string(output), err)
}
return output, err
}
func sdkSource(sdk, contents string) dagger.WithContainerFunc {
return func(c *dagger.Container) *dagger.Container {
var sourcePath string
switch sdk {
case "go":
sourcePath = "main.go"
case "python":
sourcePath = "src/main.py"
default:
return c
}
return c.WithNewFile(sourcePath, dagger.ContainerWithNewFileOpts{
Contents: contents,
})
}
}
func sdkCodegenFile(t *testing.T, sdk string) string { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Helper()
switch sdk {
case "go":
return "dagger.gen.go"
case "python":
return "sdk/src/dagger/client/gen.py"
default:
return ""
}
}
func currentSchema(ctx context.Context, t *testing.T, ctr *dagger.Container) *introspection.Schema {
t.Helper()
out, err := ctr.With(daggerQuery(introspection.Query)).Stdout(ctx)
require.NoError(t, err)
var schemaResp introspection.Response
err = json.Unmarshal([]byte(out), &schemaResp)
require.NoError(t, err)
return schemaResp.Schema
}
func goGitBase(t *testing.T, c *dagger.Client) *dagger.Container {
t.Helper()
return c.Container().From(golangImage).
WithExec([]string{"apk", "add", "git"}).
WithExec([]string{"git", "config", "--global", "user.email", "dagger@example.com"}).
WithExec([]string{"git", "config", "--global", "user.name", "Dagger Tests"}).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithExec([]string{"git", "init"})
}
func logGen(ctx context.Context, t *testing.T, modSrc *dagger.Directory) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/integration/module_test.go | t.Helper()
generated, err := modSrc.File("dagger.gen.go").Contents(ctx)
require.NoError(t, err)
t.Cleanup(func() {
t.Name()
fileName := filepath.Join(
os.TempDir(),
t.Name(),
fmt.Sprintf("dagger.gen.%d.go", time.Now().Unix()),
)
if err := os.MkdirAll(filepath.Dir(fileName), 0o755); err != nil {
t.Logf("failed to create temp dir for generated code: %v", err)
return
}
if err := os.WriteFile(fileName, []byte(generated), 0644); err != nil {
t.Logf("failed to write generated code to %s: %v", fileName, err)
} else {
t.Logf("wrote generated code to %s", fileName)
}
})
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/schema/usermod.go | package schema
import (
"bytes"
"context"
"fmt"
"sync"
"github.com/dagger/dagger/core"
"github.com/dagger/dagger/core/resourceid"
"github.com/dagger/graphql"
"github.com/moby/buildkit/util/bklog"
"github.com/opencontainers/go-digest"
"github.com/vektah/gqlparser/v2/ast"
"github.com/vektah/gqlparser/v2/formatter"
)
/*
A user defined module loaded into this server's DAG.
*/
type UserMod struct {
api *APIServer
metadata *core.Module
deps *ModDeps
sdk SDK
dagDigest digest.Digest
lazilyLoadedObjects []*UserModObject
loadObjectsErr error
loadObjectsLock sync.Mutex
}
var _ Mod = (*UserMod)(nil)
func newUserMod(api *APIServer, modMeta *core.Module, deps *ModDeps, sdk SDK) (*UserMod, error) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/schema/usermod.go | selfDigest, err := modMeta.BaseDigest()
if err != nil {
return nil, fmt.Errorf("failed to get module digest: %w", err)
}
dagDigest := digest.FromString(selfDigest.String() + " " + deps.DagDigest().String())
m := &UserMod{
api: api,
metadata: modMeta,
deps: deps,
sdk: sdk,
dagDigest: dagDigest,
}
return m, nil
}
func (m *UserMod) Name() string {
return m.metadata.Name
}
func (m *UserMod) DagDigest() digest.Digest {
return m.dagDigest
}
func (m *UserMod) Dependencies() []Mod {
return m.deps.mods
}
func (m *UserMod) Codegen(ctx context.Context) (*core.GeneratedCode, error) {
return m.sdk.Codegen(ctx, m)
}
func (m *UserMod) Runtime(ctx context.Context) (*core.Container, error) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/schema/usermod.go | return m.sdk.Runtime(ctx, m)
}
func (m *UserMod) Objects(ctx context.Context) (loadedObjects []*UserModObject, rerr error) {
m.loadObjectsLock.Lock()
defer m.loadObjectsLock.Unlock()
if len(m.lazilyLoadedObjects) > 0 {
return m.lazilyLoadedObjects, nil
}
if m.loadObjectsErr != nil {
return nil, m.loadObjectsErr
}
defer func() {
m.lazilyLoadedObjects = loadedObjects
m.loadObjectsErr = rerr
}()
runtime, err := m.Runtime(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get module runtime: %w", err)
}
getModDefFn, err := newModFunction(ctx, m, nil, runtime, core.NewFunction("", &core.TypeDef{
Kind: core.TypeDefKindObject,
AsObject: core.NewObjectTypeDef("Module", ""),
}))
if err != nil {
return nil, fmt.Errorf("failed to create module definition function for module %q: %w", m.Name(), err)
}
result, err := getModDefFn.Call(ctx, &CallOpts{Cache: true, SkipSelfSchema: true})
if err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/schema/usermod.go | return nil, fmt.Errorf("failed to call module %q to get functions: %w", m.Name(), err)
}
modMeta, ok := result.(*core.Module)
if !ok {
return nil, fmt.Errorf("expected Module result, got %T", result)
}
objs := make([]*UserModObject, 0, len(modMeta.Objects))
for _, objTypeDef := range modMeta.Objects {
if err := m.validateTypeDef(ctx, objTypeDef); err != nil {
return nil, fmt.Errorf("failed to validate type def: %w", err)
}
if err := m.namespaceTypeDef(ctx, objTypeDef); err != nil {
return nil, fmt.Errorf("failed to namespace type def: %w", err)
}
obj, err := newModObject(ctx, m, objTypeDef)
if err != nil {
return nil, fmt.Errorf("failed to create object: %w", err)
}
objs = append(objs, obj)
}
return objs, nil
}
func (m *UserMod) ModTypeFor(ctx context.Context, typeDef *core.TypeDef, checkDirectDeps bool) (ModType, bool, error) {
switch typeDef.Kind {
case core.TypeDefKindString, core.TypeDefKindInteger, core.TypeDefKindBoolean, core.TypeDefKindVoid:
return &PrimitiveType{}, true, nil
case core.TypeDefKindList:
underlyingType, ok, err := m.ModTypeFor(ctx, typeDef.AsList.ElementTypeDef, checkDirectDeps)
if err != nil {
return nil, false, fmt.Errorf("failed to get underlying type: %w", err) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/schema/usermod.go | }
if !ok {
return nil, false, nil
}
return &ListType{underlying: underlyingType}, true, nil
case core.TypeDefKindObject:
if checkDirectDeps {
depType, ok, err := m.deps.ModTypeFor(ctx, typeDef)
if err != nil {
return nil, false, fmt.Errorf("failed to get type from dependency: %w", err)
}
if ok {
return depType, true, nil
}
}
objs, err := m.Objects(ctx)
if err != nil {
return nil, false, err
}
for _, obj := range objs {
if obj.typeDef.AsObject.Name == typeDef.AsObject.Name {
return obj, true, nil
}
}
return nil, false, nil
default:
return nil, false, fmt.Errorf("unexpected type def kind %s", typeDef.Kind)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/schema/usermod.go | }
func (m *UserMod) MainModuleObject(ctx context.Context) (*UserModObject, error) {
objs, err := m.Objects(ctx)
if err != nil {
return nil, err
}
for _, obj := range objs {
if obj.typeDef.AsObject.Name == gqlObjectName(m.metadata.Name) {
return obj, nil
}
}
return nil, fmt.Errorf("failed to find main module object %q", m.metadata.Name)
}
func (m *UserMod) Schema(ctx context.Context) ([]SchemaResolvers, error) {
ctx = bklog.WithLogger(ctx, bklog.G(ctx).WithField("module", m.Name()))
bklog.G(ctx).Debug("getting module schema")
objs, err := m.Objects(ctx)
if err != nil {
return nil, err
}
schemas := make([]SchemaResolvers, 0, len(objs))
for _, obj := range objs {
objSchemaDoc, objResolvers, err := obj.Schema(ctx)
if err != nil {
return nil, err
}
buf := &bytes.Buffer{}
formatter.NewFormatter(buf).FormatSchemaDocument(objSchemaDoc)
typeSchemaStr := buf.String()
schema := StaticSchema(StaticSchemaParams{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/schema/usermod.go | Name: fmt.Sprintf("%s.%s", m.metadata.Name, obj.typeDef.AsObject.Name),
Schema: typeSchemaStr,
Resolvers: objResolvers,
})
schemas = append(schemas, schema)
}
return schemas, nil
}
func (m *UserMod) SchemaIntrospectionJSON(ctx context.Context) (string, error) {
return m.deps.SchemaIntrospectionJSON(ctx)
}
func (m *UserMod) validateTypeDef(ctx context.Context, typeDef *core.TypeDef) error {
switch typeDef.Kind {
case core.TypeDefKindList:
return m.validateTypeDef(ctx, typeDef.AsList.ElementTypeDef)
case core.TypeDefKindObject:
obj := typeDef.AsObject
modType, ok, err := m.deps.ModTypeFor(ctx, typeDef)
if err != nil {
return fmt.Errorf("failed to get mod type for type def: %w", err)
}
if ok {
if sourceMod := modType.SourceMod(); sourceMod != nil && sourceMod.DagDigest() != m.DagDigest() {
return nil
}
}
for _, field := range obj.Fields {
if gqlFieldName(field.Name) == "id" { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/schema/usermod.go | return fmt.Errorf("cannot define field with reserved name %q on object %q", field.Name, obj.Name)
}
if err := m.validateTypeDef(ctx, field.TypeDef); err != nil {
return err
}
}
for _, fn := range obj.Functions {
if gqlFieldName(fn.Name) == "id" {
return fmt.Errorf("cannot define function with reserved name %q on object %q", fn.Name, obj.Name)
}
if err := m.validateTypeDef(ctx, fn.ReturnType); err != nil {
return err
}
for _, arg := range fn.Args {
if gqlArgName(arg.Name) == "id" {
return fmt.Errorf("cannot define argument with reserved name %q on function %q", arg.Name, fn.Name)
}
if err := m.validateTypeDef(ctx, arg.TypeDef); err != nil {
return err
}
}
}
}
return nil
}
func (m *UserMod) namespaceTypeDef(ctx context.Context, typeDef *core.TypeDef) error {
switch typeDef.Kind {
case core.TypeDefKindList:
if err := m.namespaceTypeDef(ctx, typeDef.AsList.ElementTypeDef); err != nil {
return err |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/schema/usermod.go | }
case core.TypeDefKindObject:
obj := typeDef.AsObject
_, ok, err := m.deps.ModTypeFor(ctx, typeDef)
if err != nil {
return fmt.Errorf("failed to get mod type for type def: %w", err)
}
if !ok {
obj.Name = namespaceObject(obj.Name, m.metadata.Name)
}
for _, field := range obj.Fields {
if err := m.namespaceTypeDef(ctx, field.TypeDef); err != nil {
return err
}
}
for _, fn := range obj.Functions {
if err := m.namespaceTypeDef(ctx, fn.ReturnType); err != nil {
return err
}
for _, arg := range fn.Args {
if err := m.namespaceTypeDef(ctx, arg.TypeDef); err != nil {
return err
}
}
}
}
return nil
}
type UserModObject struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/schema/usermod.go | api *APIServer
mod *UserMod
typeDef *core.TypeDef
lazyLoadedFields []*UserModField
lazyLoadedFunctions []*UserModFunction
loadErr error
loadLock sync.Mutex
}
var _ ModType = (*UserModObject)(nil)
func newModObject(ctx context.Context, mod *UserMod, typeDef *core.TypeDef) (*UserModObject, error) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,286 | ๐ Zenith: camelCase automagic issues with PythonSDK | ### What is the issue?
When attempting to run the examples provided in the dagger module's documentation, I encountered two issues that presumably have the same underlying cause regarding the automatic camelCase conversion performed in the Python SDK.
## First issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#chain-modules-together)):
```python
"""A Dagger module for saying hello world!."""
from dagger import field, function, object_type
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_name(self, name: str) -> "HelloWorld":
self.name = name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.name}!"
```
And here is an example query for this module:
```graphql
{
helloWorld {
message
withName(name: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
The result is as expected
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withName": {
"withGreeting": {
"message": "Bonjour, Monde!"
}
}
}
}
```
Now, if I rename `name` to `my_name`:
```python
@object_type
class HelloWorld:
greeting: str = field(default="Hello")
my_name: str = field(default="World")
@function
def with_greeting(self, greeting: str) -> "HelloWorld":
self.greeting = greeting
return self
@function
def with_my_name(self, my_name: str) -> "HelloWorld":
self.my_name = my_name
return self
@function
def message(self) -> str:
return f"{self.greeting} {self.my_name}!"
```
and use the following query:
```graphql
{
helloWorld {
message
withMyName(myName: "Monde") {
withGreeting(greeting: "Bonjour") {
message
}
}
}
}
```
I get this result
```plain
{
"helloWorld": {
"message": "Hello, World!",
"withMyName": {
"withGreeting": {
"message": "Bonjour World!"
}
}
}
}
```
## Second issue
Take the following example (taken from [here](https://docs.dagger.io/zenith/developer/python/539756/advanced-programming#write-an-asynchronous-module-constructor-function)):
```python
"""A Dagger module for searching an input file."""
import dagger
from dagger import dag, object_type, field, function
@object_type
class Grep:
src: dagger.File = field()
@classmethod
async def create(cls, src: dagger.File | None = None):
if src is None:
src = await dag.http("https://dagger.io")
return cls(src=src)
@function
async def grep(self, pattern: str) -> str:
return await (
dag
.container()
.from_("alpine:latest")
.with_mounted_file("/src", self.src)
.with_exec(["grep", pattern, "/src"])
.stdout()
)
```
Similarly, if I alter this example by renaming `src` to `my_src`:
```python
...
@object_type
class Grep:
my_src: dagger.File = field()
@classmethod
async def create(cls, my_src: dagger.File | None = None):
if my_src is None:
my_src = await dag.http("https://dagger.io")
return cls(my_src=my_src)
...
```
I get the following error:
```shell
$ dagger call grep --pattern dagger
โ dagger call grep ERROR [1.92s]
โ Error: response from query: input:1: grep.grep failed to get function output directory: process "/runtime" did not complete successfully: exit code: 1
โ grep(pattern: "dagger") ERROR [0.85s]
โ exec /runtime ERROR [0.85s]
โ โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ /runtime:8 in <module> โ
โ โ โ
โ โ 5 from dagger.mod.cli import app โ
โ โ 6 โ
โ โ 7 if __name__ == "__main__": โ
โ โ โฑ 8 โ sys.exit(app()) โ
โ โ 9 โ
โ โ โ
โ โ /sdk/src/dagger/mod/cli.py:32 in app โ
โ โ โ
โ โ 29 โ ) โ
โ โ 30 โ try: โ
โ โ 31 โ โ mod = get_module() โ
โ โ โฑ 32 โ โ mod() โ
โ โ 33 โ except FatalError as e: โ
โ โ 34 โ โ if logger.isEnabledFor(logging.DEBUG): โ
โ โ 35 โ โ โ logger.exception("Fatal error") โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:181 in __call__ โ
โ โ โ
โ โ 178 โ def __call__(self) -> None: โ
โ โ 179 โ โ if self._log_level is not None: โ
โ โ 180 โ โ โ configure_logging(self._log_level) โ
โ โ โฑ 181 โ โ anyio.run(self._run) โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py:66 in run โ
โ โ โ
โ โ 63 โ โ
โ โ 64 โ try: โ
โ โ 65 โ โ backend_options = backend_options or {} โ
โ โ โฑ 66 โ โ return async_backend.run(func, args, {}, backend_options) โ
โ โ 67 โ finally: โ
โ โ 68 โ โ if token: โ
โ โ 69 โ โ โ sniffio.current_async_library_cvar.reset(token) โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1960 in โ
โ โ run โ
โ โ โ
โ โ 1957 โ โ debug = options.get("debug", False) โ
โ โ 1958 โ โ options.get("loop_factory", None) โ
โ โ 1959 โ โ options.get("use_uvloop", False) โ
โ โ โฑ 1960 โ โ return native_run(wrapper(), debug=debug) โ
โ โ 1961 โ โ
โ โ 1962 โ @classmethod โ
โ โ 1963 โ def current_token(cls) -> object: โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:190 in run โ
โ โ โ
โ โ 187 โ โ โ "asyncio.run() cannot be called from a running event loop" โ
โ โ 188 โ โ
โ โ 189 โ with Runner(debug=debug) as runner: โ
โ โ โฑ 190 โ โ return runner.run(main) โ
โ โ 191 โ
โ โ 192 โ
โ โ 193 def _cancel_all_tasks(loop): โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/runners.py:118 in run โ
โ โ โ
โ โ 115 โ โ โ
โ โ 116 โ โ self._interrupt_count = 0 โ
โ โ 117 โ โ try: โ
โ โ โฑ 118 โ โ โ return self._loop.run_until_complete(task) โ
โ โ 119 โ โ except exceptions.CancelledError: โ
โ โ 120 โ โ โ if self._interrupt_count > 0: โ
โ โ 121 โ โ โ โ uncancel = getattr(task, "uncancel", None) โ
โ โ โ
โ โ /usr/local/lib/python3.11/asyncio/base_events.py:653 in run_until_complete โ
โ โ โ
โ โ 650 โ โ if not future.done(): โ
โ โ 651 โ โ โ raise RuntimeError('Event loop stopped before Future comp โ
โ โ 652 โ โ โ
โ โ โฑ 653 โ โ return future.result() โ
โ โ 654 โ โ
โ โ 655 โ def stop(self): โ
โ โ 656 โ โ """Stop running the event loop. โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:1953 in โ
โ โ wrapper โ
โ โ โ
โ โ 1950 โ โ โ _task_states[task] = TaskState(None, None) โ
โ โ 1951 โ โ โ โ
โ โ 1952 โ โ โ try: โ
โ โ โฑ 1953 โ โ โ โ return await func(*args) โ
โ โ 1954 โ โ โ finally: โ
โ โ 1955 โ โ โ โ del _task_states[task] โ
โ โ 1956 โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:185 in _run โ
โ โ โ
โ โ 182 โ โ
โ โ 183 โ async def _run(self): โ
โ โ 184 โ โ async with await dagger.connect(): โ
โ โ โฑ 185 โ โ โ await self._serve() โ
โ โ 186 โ โ
โ โ 187 โ async def _serve(self): โ
โ โ 188 โ โ mod_name = await self._mod.name() โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:193 in _serve โ
โ โ โ
โ โ 190 โ โ resolvers = self.get_resolvers(mod_name) โ
โ โ 191 โ โ โ
โ โ 192 โ โ result = ( โ
โ โ โฑ 193 โ โ โ await self._invoke(resolvers, parent_name) โ
โ โ 194 โ โ โ if parent_name โ
โ โ 195 โ โ โ else await self._register(resolvers, to_pascal_case(mod_na โ
โ โ 196 โ โ ) โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:266 in _invoke โ
โ โ โ
โ โ 263 โ โ ) โ
โ โ 264 โ โ โ
โ โ 265 โ โ resolver = self.get_resolver(resolvers, parent_name, name) โ
โ โ โฑ 266 โ โ return await self.get_result(resolver, parent_json, inputs) โ
โ โ 267 โ โ
โ โ 268 โ async def get_result( โ
โ โ 269 โ โ self, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:279 in get_result โ
โ โ โ
โ โ 276 โ โ โ isinstance(resolver, FunctionResolver) โ
โ โ 277 โ โ โ and inspect.isclass(resolver.wrapped_func) โ
โ โ 278 โ โ ): โ
โ โ โฑ 279 โ โ โ root = await self.get_root(resolver.origin, parent_json) โ
โ โ 280 โ โ โ
โ โ 281 โ โ try: โ
โ โ 282 โ โ โ result = await resolver.get_result(self._converter, root, โ
โ โ โ
โ โ /sdk/src/dagger/mod/_module.py:325 in get_root โ
โ โ โ
โ โ 322 โ โ if not parent: โ
โ โ 323 โ โ โ return origin() โ
โ โ 324 โ โ โ
โ โ โฑ 325 โ โ return await asyncify(self._converter.structure, parent, origi โ
โ โ 326 โ โ
โ โ 327 โ def field( โ
โ โ 328 โ โ self, โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/to_thread.py:49 in run_sync โ
โ โ โ
โ โ 46 โ โ โ stacklevel=2, โ
โ โ 47 โ โ ) โ
โ โ 48 โ โ
โ โ โฑ 49 โ return await get_async_backend().run_sync_in_worker_thread( โ
โ โ 50 โ โ func, args, abandon_on_cancel=abandon_on_cancel, limiter=limite โ
โ โ 51 โ ) โ
โ โ 52 โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:2103 in โ
โ โ run_sync_in_worker_thread โ
โ โ โ
โ โ 2100 โ โ โ โ โ worker_scope = scope._parent_scope โ
โ โ 2101 โ โ โ โ โ
โ โ 2102 โ โ โ โ worker.queue.put_nowait((context, func, args, future, โ
โ โ โฑ 2103 โ โ โ โ return await future โ
โ โ 2104 โ โ
โ โ 2105 โ @classmethod โ
โ โ 2106 โ def check_cancelled(cls) -> None: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py:823 in โ
โ โ run โ
โ โ โ
โ โ 820 โ โ โ โ โ exception: BaseException | None = None โ
โ โ 821 โ โ โ โ โ threadlocals.current_cancel_scope = cancel_scope โ
โ โ 822 โ โ โ โ โ try: โ
โ โ โฑ 823 โ โ โ โ โ โ result = context.run(func, *args) โ
โ โ 824 โ โ โ โ โ except BaseException as exc: โ
โ โ 825 โ โ โ โ โ โ exception = exc โ
โ โ 826 โ โ โ โ โ finally: โ
โ โ โ
โ โ /usr/local/lib/python3.11/site-packages/cattrs/converters.py:332 in โ
โ โ structure โ
โ โ โ
โ โ 329 โ โ
โ โ 330 โ def structure(self, obj: Any, cl: Type[T]) -> T: โ
โ โ 331 โ โ """Convert unstructured Python data structures to structured โ
โ โ โฑ 332 โ โ return self._structure_func.dispatch(cl)(obj, cl) โ
โ โ 333 โ โ
โ โ 334 โ # Classes to Python primitives. โ
โ โ 335 โ def unstructure_attrs_asdict(self, obj: Any) -> Dict[str, Any]: โ
โ โ in structure_Grep:9 โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ClassValidationError: While structuring Grep (1 sub-exception)
โข Engine: 9e91eb66912d (version v0.9.4)
โง 20.86s โ 112 โ
16 โ 3
```
### Dagger version
dagger v0.9.4 (registry.dagger.io/engine) darwin/arm64
### Steps to reproduce
_No response_
### Log output
_No response_ | https://github.com/dagger/dagger/issues/6286 | https://github.com/dagger/dagger/pull/6287 | 1502402c4c028f15165a14ea8f05260057c8141e | 62e02912129760bc86c309e5107dd7eb463ac2bf | 2023-12-16T16:19:10Z | go | 2023-12-20T11:15:41Z | core/schema/usermod.go | if typeDef.Kind != core.TypeDefKindObject {
return nil, fmt.Errorf("expected object type def, got %s", typeDef.Kind)
}
obj := &UserModObject{
api: mod.api,
mod: mod,
typeDef: typeDef,
}
return obj, nil
}
func (obj *UserModObject) TypeDef() *core.TypeDef {
return obj.typeDef
}
func (obj *UserModObject) ConvertFromSDKResult(ctx context.Context, value any) (any, error) {
if value == nil {
return nil, nil
}
switch value := value.(type) {
case string:
decodedMap, err := resourceid.DecodeModuleID(value, obj.typeDef.AsObject.Name)
if err != nil {
return nil, fmt.Errorf("failed to decode module id: %w", err)
}
return obj.ConvertFromSDKResult(ctx, decodedMap)
case map[string]any:
for k, v := range value {
normalizedName := gqlFieldName(k) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.