sjyangkevin commented on issue #63279:
URL: https://github.com/apache/airflow/issues/63279#issuecomment-4041514437

   Tested #62604 with the following DAG code and test scenarios, and looks good.
   
   1. ✔️ Set `requirements=["pendulum"]`
   2. ✔️ Set `requirements=["pendulum>=3"]`
   3. ✔️ Set `requirements=["pendulum<3"]`
   4. ❌ Set `requirements=None`
   5. ❌ Set `requirements=["<other packages>"]`
   
   The `generate_message` imports `pendulum` and it requires `pendulum` to be 
specified in the `requirements`. If the `pendulum` is not specified, it will 
raise an import error.
   
   <img width="1152" height="272" alt="Image" 
src="https://github.com/user-attachments/assets/cdba5b61-63d3-4ea6-9e6b-777b20a9a924";
 />
   
   ### DAG code
   ```python
   from datetime import datetime, timedelta
   import pendulum
   from airflow import DAG
   
   from airflow.providers.standard.operators.python import PythonOperator, 
PythonVirtualenvOperator
   
   
   # Define the DAG
   with DAG(dag_id="example_virtualenv_dag", start_date=datetime(2025, 5, 1), 
schedule=None, catchup=False) as dag:
   
       # A simple Python callable to be run in the virtualenv
       def generate_message(*args, **kwargs):
           import pendulum
           return f"Hello from virtualenv! pendulum version 
{pendulum.__version__}"
   
       # Task: runs `generate_message` inside a fresh virtual environment
       virtualenv_task = PythonVirtualenvOperator(
           task_id="virtualenv_task",
           python_version="3.9",
           python_callable=generate_message,
           requirements=[
               "pendulum"
           ],  # This will cause an error: AttributeError: type object 
'Timezone' has no attribute '_unpickle'
           system_site_packages=False,
           expect_airflow=False,
           serializer="dill",
       )
   
   
   if __name__ == "__main__":
       dag_run = dag.test(
           logical_date=pendulum.datetime(2025, 5, 3)
       )  # Runs all tasks locally without a scheduler 
:contentReference[oaicite:2]{index=2}
       print("STATE: ", dag_run.state)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to