GitHub user tgrandje added a comment to the discussion: sqlalchemy 2 set in a 
virtualenv breaks variable access

> Ah OK I get your issue. it's not about virtual env it's about variables.
> 
> You are doing it wrong. You can not do `Variable.get()` inside virtual env. 
> You should use `op_args` / `op_kwargs` and pass the variable to the 
> environment using Jinja macro `{{ var.value.<variable_name> }}`

@eladkal You sure about that? I hadn't had any trouble up to now. For instance, 
that dag will run get_variable3 just fine:
```
from airflow.decorators import dag, task


@dag()
def sqlalchemy_test():

    from airflow.models import Variable

    Variable.set("eggs", "spam")

    @task
    def get_variable():
        from airflow.models import Variable

        print(Variable.get("eggs"))

    @task.virtualenv(requirements=["sqlalchemy>2.0.0"])
    def get_variable2():
        from airflow.models import Variable

        print(Variable.get("eggs"))

    @task.virtualenv(requirements=["geopandas"])
    def get_variable3():
        from airflow.models import Variable

        print(Variable.get("eggs"))

    get_variable()
    get_variable2()
    get_variable3()


sqlalchemy_test()
```

GitHub link: 
https://github.com/apache/airflow/discussions/46266#discussioncomment-12001260

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]

Reply via email to