Skip to content

Add an include mode for infra.apply #117

Open

Description

@sdascoli

In some cases where we know exactly on which model field an infra should depend, it would be much easier and safer to have a mode infra.apply(include_in_cache_uid).
Easier because it avoids copying all model fields.
Safer because if we subsequently add fields during the class development, we don't have to remember to add the new field in the exclude_from_cache_uid

Activity

  1. sdascoli commented on Oct 8, 2025

    @sdascoli
    ContributorAuthor

    The lack of this feature is particularly annoying in the following situation:

    class Foo(BaseModel):
      foo1: str
      lots of other keys...
    
    class Bar(BaseModel):
      bar1: str
      lots of other keys...
    
    class MyClass(BaseModel):
      foo: Foo
      bar: Bar
      infra: TaskInfra

    Imagine if we only want infra to depend on foo.bar1.
    With the include logic, we could do infra.apply(include="foo.foo1")
    With the current logic, it is impossible to do this: we would have to do sth horribly hacky like this (had to do in my pipeline)

    def exclude(cls):
            out = [k for k in cls.model_fields.keys()]
            out.remove("foo")
            out += ["foo."+k for k in Foo.model_fields.keys()]
            out.remove("foo.bar1")
    
  2. kingjr commented on Oct 9, 2025

    @kingjr
    Contributor

    The include exclude logic would become quite hard.

    Can’t you simply use _ for the excluded params ? Eg _foo, _bar , this automatically exclude

  3. sdascoli commented on Oct 9, 2025

    @sdascoli
    ContributorAuthor

    The include exclude logic would become quite hard.

    Can’t you simply use _ for the excluded params ? Eg _foo, _bar , this automatically exclude

    No because I have multiple infras on my object which depend on different fields…
    Why do you think this would be hard? If it’s too complex we could make them mutually exclusive in which case it would be easy

  4. kingjr commented on Oct 9, 2025

    @kingjr
    Contributor

    Yes, we could add include_only.

    My gut feeling is that this need is diagnostic of an improvable class design, but we'd need to discuss this with concrete examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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