Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injected Adapter can't access Context from parent #456

Closed
TyrianOtter opened this issue Oct 2, 2024 · 1 comment
Closed

Injected Adapter can't access Context from parent #456

TyrianOtter opened this issue Oct 2, 2024 · 1 comment

Comments

@TyrianOtter
Copy link
Contributor

When an adapter is injected, it doesn't get its provider updated from its new parent, so it can't access the context it should, as see in the following:

from refiners.fluxion.adapters.adapter import Adapter
from refiners.fluxion.context import Contexts
import refiners.fluxion.layers as fl

class P(fl.Chain):
    def init_context(self) -> Contexts:
        return {'foo': {'bar': None}}

class A(fl.Chain, Adapter[fl.Chain]):
    def __init__(self, target: fl.Chain):
        with self.setup_adapter(target):
            super().__init__(
                fl.Lambda(lambda: 1),
                fl.SetContext('foo', 'bar'),
            )

    def inject(self, parent: fl.Chain | None = None):
        x = super().inject(parent)
        return x

m = P(
    fl.Chain(
        fl.Lambda(lambda: 1),
        fl.SetContext('foo', 'bar'),
    ),
    fl.UseContext('foo', 'bar'),
)
c, parent = next(m.walk(fl.Chain))

m() # no error
A(c).inject(parent)
# m._register_provider() # uncommenting this stops the next line's error
m() # error: "Context foo not found."
@catwell
Copy link
Member

catwell commented Oct 3, 2024

Fixed by #457 - thanks for the report!

@catwell catwell closed this as completed Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants