Skip to content

Injected Adapter can't access Context from parent #456

@TyrianOtter

Description

@TyrianOtter

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."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions