Hi, I have some troubles running a flow. This is t...
# prefect-server
s
Hi, I have some troubles running a flow. This is the context. I have a repo that contains all the flows, and another repo that keep shared code between them (
ec2_instances
and others). In
ec2_instances.py
there are 3 task methods, and in this way it works. However, since I made a refactor in that file in order to add some behavior I needed, it’s failing. I added some non-task methods that are going to be invoked in the existing task methods. The error that is being thrown is:
Copy code
Failed to load and execute Flow's environment: StorageError('An error occurred while unpickling the flow:\n  AttributeError("Can\'t get attribute \'get_boto_client_with_auth\' on <module \'...ec2_instances\' from \'/usr/local/lib/python3.7/site-packages/automation_library/ec2_instances.py\'>")\nThis may be due to one of the following version mismatches between the flow build and execution environments:\n  - cloudpickle: (flow built with \'1.6.0\', currently running with \'2.0.0\')\n  - python: (flow built with \'3.7.9\', currently running with \'3.7.12\')')
Why is it failing only when I add non-task methods? Does it make any sense?
a
As the error message says, it’s not because of your custom modules but rather due to a mismatch of environments. You can avoid such issues either by: 1. Using script storage - e.g. stored_as_script=True set on the storage class 2. Ensuring that the same version is used in the flow registration environment as the Prefect and cloudpickle version used by your agent Lastly, since you are using Server, you also need to ensure that your Server Prefect version is >= Prefect version used by your agent and registration environment
This error indicates that your custom module is not packaged appropriately:
Copy code
AttributeError("Can\'t get attribute \'get_boto_client_with_auth\' on <module
Did you install this as a package on your agent? what agent do you use? what is your Storage and run configuration?
s
That is a method inside of a file located in a github repo, that have already installed in the repo, where the flow lives. Then I register it, from there. It’s werid, because If I take the method
get_boto_client_with_auth
and move it into a task method, as an internal method of another function, it works.
So it seems that the error is not related to library versions, as it looks
a
does it mean you use some Git-storage class? Having the file in the repo is not enough unfortunately, it must be installed in the execution environment used by your agent
s
Not, in dev environment we are using S3 Storage for the code
a
yeah, the same with S3. You need to package your code as a package and install on your agent. Even doing something like rsync to ensure your agent has the same environment as your registration environment. If you need some examples, you can check this repo. LMK if you have any specific questions I can help with
s
If I remove the method, and I move it’s code into another task method, that is not required. Since it works, So what is the reason for that? Why do I need to do that only for this? Is there any work around or maybe a easy way to do this ? The agent is running in a EC2 Instance, and it is not pretty to install the package every time it is updated.
a
that’s the disadvantage of using a local agent unfortunately. You could set up Docker agent on the same EC2 instance which would allow you to e.g. pull the image from ECR and provide more dependency isolation between workflows. If you need a hacky workaround (I don’t recommend it because it’s a hack): you can install your package in the editable mode:
Copy code
pip install -e .
and then e.g. on your CI/CD push the code changes to S3 and on the EC2 instance you can build e.g. a cron job that regularly syncs the code from S3 to your instance:
Copy code
aws s3 sync <s3://yourbucket/your_code> /path/to/your_code