Hello, team! I have one question. I have created a...
# dev-metaflow
h
Hello, team! I have one question. I have created a few flows (A, B and C). These flows share a lot of functionalities. My idea was to create super class D that inherits FlowSpec class. Created flows (A, B and C) would inherit the super class D. But, there is a problem. In step methods (from class A), I can't see attributes from the super class. I think super class constructor is not called before. While reading documentation, I found that variables are being serialized into memory and being deserialized after. I don't understand why constructor of super class isn't called (I explicitly called constructor). What do you think about it?
1
s
hi Kristijan!
🙌 1
i.e. you can have superclasses that don't derive from
FlowSpec
. You can assign artifacts to
self
in the superclass
constructors are not called since Metaflow classes get instantiated multiple times in different contexts. Usually you can use the
start
step,
Parameters
, custom methods/decorators, or deploy-time functions to execute your own initialization code at the right time in the flow's lifecycle
🙌 1
thankyou 1
h
1. If I understand, multiple inheritance will solve a problem? 2. Are super class artifacts shared between different contexts? 3. What do you recommend for using environment variables? To use parameters via environment variables with prefix METAFLOW_RUN_? 4. Can I have start step method in super class and then use it in sub class start step method? My main problem is to calculate some string from begin, and use it in different steps after.
s
1. Yes, multiple inheritance allows you to use a superclass. 2. Yes, they work like any other artifacts. 3. Right, you can use environment variables to set parameters if you want.
re: 4, something like this works:
Copy code
class MyModel():
    def init(self):
         self.my_string = compute()

class MyFlow(FlowSpec, MyModel):
     @step
     def start(self):
          self.init()
then
<http://self.my|self.my>_string
is available in all subsequent steps
h
Thank you, @straight-shampoo-11124. You helped me a lot.
🙌 1