medihack
12/18/2021, 5:30 PMRootInputManager
. For me it would make sense to use it the same way I use a IOManager
. That way I can use the same Manager that inherits from both classes, something like this:
class DatabaseManager(RootInputManager, IOManager):
def handle_output(self, context, obj):
...
def load_input(self, context):
...
@io_manager(required_resource_keys={"database_client"})
def database_io_manager():
return DatabaseManager()
@root_input_manager(required_resource_keys={"database_client"})
def database_root_manager(_):
return DatabaseManager()
But unfortunately, it doesn't seem to work that way. The load_input
is never called when using DatabaseManager
as a root input. I just get a type check error. I guess because database_root_manager
should not return the RootInputManager
, but the input data itself. This makes it so different from each other when both cases could be so nicely combined. Or do I miss something here?
EDIT:
I found the following workaround, but still think that it is quite ugly.
@root_input_manager(required_resource_keys={"database_client"})
def database_root_manager(context: InputContext):
manager = DatabaseManager()
return manager.load_input(context)
In my opinion @root_input_manager
tries to do to much magic here (by creating it's own RootInputManager
). I would prefer that it works exactly like @io_manager
. What do you think?owen
12/20/2021, 5:29 PMroot_input_manager
will only need to define a single function (load_input
), and so the overhead of creating an entire wrapper class for that purpose is pretty undesirable. However, in cases like yours, there isn't really any overhead because you already defined the class for the IOManager. These cases where you can use an IOManager as a RootInputManager are a bit rarer, simply because IOManagers often use context.upstream_output
in their load_input
functions (because they store the outputs using schemes that rely on information specific to the output context).