Hello ! We had an issue internally after witching to Rez 3.4.0, where sometimes the ephemerals binding inside commands would be empty.
This was not the case for context.resolved_ephemerals, nor for the created REZ_USED_EPH_RESOLVE and REZ_EPH_<PKG>_REQUEST environment variables.
This does happen (or not) consistently for any given request, but does not happen for every request, if that makes sense.
One of the factors I could determine was if there was another late bound function in the package.
Environment
- OS: Windows
- Rez version: 3.4.0
- Rez python version: Python 3.13.8
To Reproduce
I wrote a small script to reproduce the issue.
The script creates a simple package that accesses ephemerals inside commands and has a late bound function, and marks whether it found a particular ephemeral.
It then resolves a context with this package and the expected ephemeral, and compares what was seen in commands with the actual resolution (the context resolved_ephemerals and environment variables injected by Rez on resolution).
You can run it with rez python ./path/to/script.py.
import tempfile
from pathlib import Path
from rez.resolved_context import ResolvedContext
PACKAGE_PY = """
name = "foo"
version = "1.0"
@late()
def requires():
return []
def commands():
if "myeph" in ephemerals:
env.EPH_SEEN_IN_COMMANDS = "1"
else:
env.EPH_SEEN_IN_COMMANDS = "0"
"""
def main():
with tempfile.TemporaryDirectory(prefix="repro_case_empty_ephemerals_") as temp:
package_repository = Path(temp)
package_definition = package_repository / "foo" / "1.0" / "package.py"
package_definition.parent.mkdir(parents=True, exist_ok=True)
package_definition.write_text(PACKAGE_PY)
context = ResolvedContext(
["foo", ".myeph-1"], package_paths=[str(package_repository)]
)
environ = context.get_environ()
from_context = context.resolved_ephemerals
from_env = environ.get("REZ_USED_EPH_RESOLVE")
seen_in_commands = environ.get("EPH_SEEN_IN_COMMANDS")
print(f"Ephemerals from `context.resolved_ephemerals`: {from_context}")
print(f"Ephemerals from `REZ_USED_EPH_RESOLVE`: {from_env}")
print(f"Ephemeral seen in `commands`: {seen_in_commands}")
did_resolve = bool(from_context) and bool(from_env)
if did_resolve and seen_in_commands != "1":
print(
"Ephemeral was resolved but absent from `ephemerals` inside `commands`"
)
if __name__ == "__main__":
main()
Expected behavior
An ephemerals binding matching context.resolved_ephemerals and the associated environment variables.
Actual behavior
Empty ephemerals binding.
Related Issues/PRs
Regression
The bug only affects the ephemerals binding, and is seemingly caused by the recent change introduced in #2117.
Internally, we found a few possible workarounds (such as using context.resolved_ephemerals in a late bound arbitrary attribute), and are working on a fix. It will probably be a patch to rez.resolved_context.ResolvedContext._get_pre_resolve_bindings that avoids caching ephemerals with other bindings, as ephemerals can be filled during the resolution.
Hello ! We had an issue internally after witching to Rez 3.4.0, where sometimes the
ephemeralsbinding insidecommandswould be empty.This was not the case for
context.resolved_ephemerals, nor for the createdREZ_USED_EPH_RESOLVEandREZ_EPH_<PKG>_REQUESTenvironment variables.This does happen (or not) consistently for any given request, but does not happen for every request, if that makes sense.
One of the factors I could determine was if there was another late bound function in the package.
Environment
To Reproduce
I wrote a small script to reproduce the issue.
The script creates a simple package that accesses
ephemeralsinsidecommandsand has a late bound function, and marks whether it found a particular ephemeral.It then resolves a context with this package and the expected ephemeral, and compares what was seen in
commandswith the actual resolution (the contextresolved_ephemeralsand environment variables injected by Rez on resolution).You can run it with
rez python ./path/to/script.py.Expected behavior
An
ephemeralsbinding matchingcontext.resolved_ephemeralsand the associated environment variables.Actual behavior
Empty
ephemeralsbinding.Related Issues/PRs
Regression
The bug only affects the
ephemeralsbinding, and is seemingly caused by the recent change introduced in #2117.Internally, we found a few possible workarounds (such as using
context.resolved_ephemeralsin a late bound arbitrary attribute), and are working on a fix. It will probably be a patch torez.resolved_context.ResolvedContext._get_pre_resolve_bindingsthat avoids cachingephemeralswith other bindings, as ephemerals can be filled during the resolution.