google / google/go-jsonnet

Bug with Python bindings and nested imports

Open
#528 1 comment 0 reactions 0 assignees View on GitHub
bug release-blocker
Dominant language
Go
Stars
1.8k
Forks
263
PR merge metrics
No merged PRs in 30d

Description

I have tried to come up with the simplest example I can to demonstrate this bug:
```python
import textwrap

import _gojsonnet

file_dict = {
"file1.libsonnet": textwrap.dedent(
"""
local funcImport = import "file2.libsonnet";
{
my_key: funcImport.sampleFunc()
}
"""
),
"file2.libsonnet": textwrap.dedent(
"""
local sampleFunc = function() (
3
);

{
sampleFunc:: sampleFunc
}
"""
),
}

def import_callback(from_dir, import_str):
print(f"Importing {import_str}")
return from_dir, file_dict[import_str]

def main():
snippet = textwrap.dedent(
"""
local data = import "file1.libsonnet";
data
"""
)
data = _gojsonnet.evaluate_snippet(
"test_file",
snippet,
import_callback=import_callback,
)
print(data)

if __name__ == "__main__":
main()
```

Output:
```
$ python3 py_binding.py
Importing file1.libsonnet
Importing file2.libsonnet
Traceback (most recent call last):
File "/Users/cayoub/Desktop/reproducer/py_binding.py", line 49, in
main()
File "/Users/cayoub/Desktop/reproducer/py_binding.py", line 40, in main
data = _gojsonnet.evaluate_snippet(
RuntimeError: RUNTIME ERROR: Field does not exist: sampleFunc
4:13-34 object
During manifestation
```

I am running `Python 3.9.4` with `gojsonnet==0.17.0`.

This problem seems to be unique to the Python bindings from what I can tell. When I create these 3 files normally and run with the `jsonnet` CLI command, it works without issue:
```
$ jsonnet fileMain.libsonnet
{
"my_key": 3
}
```

Let me know if there is further information I should provide for this. This is the only thing preventing us from migrating from the C++ version (where our Python code works without issue).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.