question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

inheritance & dependencies

See original GitHub issue

Hello! You helped me out already more than once, but I admit I’m getting tremendously frustrated, as I just don’t have an adequate insight to what is happening under the hood.

Let me sketch my problem – my current code has gone through so many failed experiments I’m sure it looks ridiculous.

I have a Problem container (for a machine learning problem), and two hierarchies of other containers:

ProblemView -> Conjoiner -> GroundConjoiner

ProblemView -> CutsContext

Here, problem view refers to a problem via:

class ProblemView(containers.DeclarativeContainer):

    problem = providers.DependenciesContainer()

And it takes optional dependencies that override parts of Problem, e.g.:

    ...
    weight: Provider[xr.DataArray] = providers.Dependency(
        instance_of=xr.DataArray
    )
    weight.override(problem.training.provided.weight)

Then it redefines parts of problem based on possibly overridden values:

    training = providers.Callable(
        override_weight, problem.training.provided, weight.provided
    )

ProblemView works on its own.

Next, Conjoiner is a problem view (Or has a problem view – though I’d prefer is a problem view so it can inherit “has a problem” – but either way I can’t get it to work). It takes a CutsContext as a dependency.


@container.copy(ProblemView)
class Conjoiner(ProblemView):
    cuts = providers.Container(CutsContext)

And GroundConjoiner (among others) is a Conjoiner; it provides a CutsContext to parent Conjoiner with given overall problem and weights (as well as some other customization specific to CutsContext).

@container.copy(Conjoiner)
class GroundConjoiner(Conjoiner):
    problem = Conjoiner.problem    # or...?
    weight = Conjoiner.weight

    # also tried (and same for weight)
    # problem_ = Conjoiner.problem
    # problem = providers.DependenciesContainer()
    # problem_.override(problem)

    ground_cuts_context = providers.Container(
        Cuts,
        problem=problem, weight=weight
        ...
    )
    cuts_context = ground_cuts_context.provided 

Instantiation:

gc = GroundConjoiner(problem=problem, weight=weight)

I have tried different permutations all weekend (under a looming deadline 😦), and can generate many different errors (either some dependency not defined, or – e.g. src/dependency_injector/providers.pyx:1080: in dependency_injector.providers.ConfigurationOption.__init__: TypeError: cannot create weak reference to 'dependency_injector.providers.ProvidedInstance' object), but I can’t glean from the documentation any insight into what is going on sufficient to alight on a correct solution (or even a clear bug report).

I’ll be very grateful for any help!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rmk135commented, Jan 11, 2021

Hey @shaunc , I’ll take a look. Will take some time for debugging. I’ll get back as soon as I got something.

0reactions
rmk135commented, Jan 19, 2021

Glad to help! Thanks for your patience and input to make Dependency Injector to be a better tool.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inherited Dependencies - TechDocs - Broadcom Inc.
When the server selects jobs for submission, it checks the relationships between jobs and determines whether jobs should inherit dependencies.
Read more >
Maven - Dependency Inheritance - Provided - Stack Overflow
The problem I am having is while it aggregates the POM with those dependencies, it appears when I declare dependencies of scope, provided,...
Read more >
Dependency and Inheritance - ICS, UCI
Dependency and Inheritance. A simple line between an actor and a use case means that that actor is expected to perform that use...
Read more >
Introduction to the Dependency Mechanism - Apache Maven
The dependency management section is a mechanism for centralizing dependency information. When you have a set of projects that inherit from a ...
Read more >
This inheritance causes circular dependencies between ...
An inheritance structure results in circular dependency among nested classes, that is, two classes inheriting from each other.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found