Dessia-tech / dessia_common

GNU Lesser General Public License v2.1
1 stars 2 forks source link

Fix: object_default/schema #677

Closed younesdessia closed 7 months ago

younesdessia commented 8 months ago
younesdessia commented 8 months ago

@GhislainJ here is a case of reproduction

from typing import Optional
from dessia_common.core import DessiaObject

class ObjectTest(DessiaObject):

    def __init__(self, name: str = "", measure: float = 1.1):
        self.measure = measure
        DessiaObject.__init__(self, name=name)

class InstantiateObject(DessiaObject):

    def __init__(self, name: str = ""):
        DessiaObject.__init__(self, name=name)

    def compute(self, my_object: Optional[ObjectTest] = None):
        return 404
from dessia_common.typings import MethodType
from dessia_common.workflow.blocks import InstantiateModel, ModelMethod
from dessia_common.workflow.core import Pipe, Workflow
from navalgroup_custom.dev_dc import InstantiateObject

block_0 = InstantiateModel(model_class=InstantiateObject, name="InstantateObject")
block_1 = ModelMethod(method_type=MethodType(InstantiateObject, 'compute'), name="compute")
blocks = [block_0, block_1]

pipe_1 = Pipe(block_0.outputs[0], block_1.inputs[0])

workflow = Workflow(blocks, [pipe_1], output=block_1.outputs[0], name="test")
younesdessia commented 8 months ago

Hi @GhislainJ

I checked with debug mode, for me there is no other problem except in the method object_default, and the fix is correct.

to reprduce the issue you can just do this: workflow.method_schemas

younesdessia commented 8 months ago

Another fix, replace None value of default_value with UNDEFINED in SchemaAttribute class:

image

GhislainJ commented 7 months ago

Approved but adding tests are needed to merge

younesdessia commented 7 months ago

Done !