[ 
https://issues.apache.org/jira/browse/AIRFLOW-3157?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Kaxil Naik resolved AIRFLOW-3157.
---------------------------------
    Resolution: Fixed

Resolved by 
https://github.com/apache/airflow/commit/979f4524e0ffcd28d33e83605cdf59ce777d0c13

> Variable.set shouldn't accept types other than string when JSON mode is False
> -----------------------------------------------------------------------------
>
>                 Key: AIRFLOW-3157
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-3157
>             Project: Apache Airflow
>          Issue Type: Bug
>    Affects Versions: 1.10.0
>            Reporter: jack
>            Priority: Minor
>             Fix For: 1.10.4
>
>
> Assume the following code  (My xcom contains: {color:#333333}7764615{color} ):
> {code:java}
> def set_last_orderid_variable(ds, **kwargs):
>     ti = kwargs['ti']
>     new_orderid = ti.xcom_pull(task_ids='get_max_order_id')
>     str = "Changed variable from {0} to 
> {1}".format(LAST_IMPORTED_ORDER_ID,new_orderid)
>     Variable.set('last_order_id_imported', new_orderid)
>     logging.info(str)
>     return{code}
>  
>  
> Log shows:
> {code:java}
> [2018-10-04 12:49:48,186] {base_task_runner.py:98} INFO - Subtask: 
> [2018-10-04 12:49:38,169] {orders_dag.py:400} INFO - Changed variable from 10 
> to 7764615{code}
>  
> However  When I go to variable
> {code:java}
>  'last_order_id_imported' {code}
> I see empty cell on the Value. *It changed it from 10 to nothing*.
>  
>  
> If I'll change my code to :
> {code:java}
> def set_last_orderid_variable(ds, **kwargs):
>     ti = kwargs['ti']
>     new_orderid = ti.xcom_pull(task_ids='get_max_order_id')
>     str = "Changed variable from {0} to 
> {1}".format(LAST_IMPORTED_ORDER_ID,new_orderid)
>     x = '{0}'.format(new_orderid)
>     logging.info(type(new_orderid))
>     Variable.set('last_order_id_imported', x)
>     logging.info(str)
>     return{code}
>  
>  
> This code works.
> When I go to variable
> {code:java}
>  'last_order_id_imported' {code}
> I see {color:#333333}7764615{color} 
> The log shows me:
> {code:java}
> [2018-10-04 12:53:58,002] {base_task_runner.py:98} INFO - Subtask: 
> [2018-10-04 12:53:58,002] {orders_dag.py:399} INFO - <type 'long'> 
> [2018-10-04 12:53:58,032] {base_task_runner.py:98} INFO - Subtask: 
> [2018-10-04 12:53:58,031] {orders_dag.py:401} INFO - Changed variable from 10 
> to 7764615{code}
>  
>  
> As you can see the type of new_orderid is
> {code:java}
>  long{code}
> .  Apparently the
> {code:java}
> Variable.set {code}
> can't handle it (let me remind that this value was received from xcom).
>  
>  
> If by design Variable.set can accept specific types (strings/ json etc...) it 
> should raise exception for others (long etc...) . It shouldn't deicide that 
> it puts empty string on it's own and mark the task as success.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to